Skip to content

Commit

Permalink
[#22] 메인버튼 커스텀뷰 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
yuni-ju committed Mar 22, 2022
1 parent 75ecb96 commit bc920ee
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.moyerun.moyeorun_android.views

import android.content.Context
import android.util.AttributeSet
import com.google.android.material.button.MaterialButton
import com.moyerun.moyeorun_android.R

class DefaultButton @JvmOverloads constructor(
context: Context,
attributeSet: AttributeSet,
defStyleAttr: Int = R.attr.DefaultButtonStyle
) : MaterialButton(context, attributeSet, defStyleAttr) {

init {
val typedArray = context.obtainStyledAttributes(attributeSet, R.styleable.DefaultButton)
val roundButton = typedArray.getBoolean(R.styleable.DefaultButton_roundButton, false)
if(roundButton) this.setCornerRadiusResource(R.dimen.roundButtonRadius)
typedArray.recycle()
}
}
7 changes: 7 additions & 0 deletions app/src/main/res/color/selector_button_default.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/main_blue"
android:state_enabled="true" />
<item android:color="@color/button_enable_false"
android:state_enabled="false" />
</selector>
9 changes: 9 additions & 0 deletions app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="DefaultButton">
<attr name="backgroundTint"/>
<attr name="roundButton" format="boolean"/>
</declare-styleable>

<attr name="DefaultButtonStyle" format="reference"/>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
<color name="main_light_blue">#EEF4FF</color>

<!-- extra colors -->
<color name="button_enable_false">#C4C4C4</color>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="squareButtonRadius">0dp</dimen>
<dimen name="roundButtonRadius">4dp</dimen>
</resources>
7 changes: 7 additions & 0 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<item name="android:colorBackground">@color/main_white</item>
<item name="DefaultButtonStyle">@style/DefaultButton</item>
</style>

<style name="DefaultButton" parent="Widget.MaterialComponents.Button">
<item name="android:textColor">@color/main_white</item>
<item name="backgroundTint">@color/selector_button_default</item>
<item name="cornerRadius">@dimen/squareButtonRadius</item>
</style>
</resources>

0 comments on commit bc920ee

Please sign in to comment.