Skip to content

Commit

Permalink
[#22] RectangleButton, RoundButton Style 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
yuni-ju committed Apr 13, 2022
1 parent 824275e commit 0a84c3c
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,11 @@ package com.moyerun.moyeorun_android.views

import android.content.Context
import android.util.AttributeSet
import androidx.appcompat.content.res.AppCompatResources.getDrawable
import android.view.ContextThemeWrapper
import androidx.appcompat.widget.AppCompatButton
import androidx.core.content.ContextCompat
import com.moyerun.moyeorun_android.R

class RectangleButton constructor(
context: Context,
attributeSet: AttributeSet
) : AppCompatButton(context, attributeSet) {

init {
val typedArray = context.obtainStyledAttributes(attributeSet, R.styleable.RectangleButton)

val initialBackground = typedArray.getDrawable(R.styleable.RectangleButton_android_background)
this.background = initialBackground ?: getDrawable(context, R.drawable.shape_rectangle_button)

val initialTextColor = typedArray.getColor(R.styleable.RectangleButton_android_textColor, ContextCompat.getColor(context, R.color.main_white))
this.setTextColor(initialTextColor)

this.textSize = 21F

typedArray.recycle()
}
}
attrs: AttributeSet? = null
) : AppCompatButton(ContextThemeWrapper(context, R.style.RectangleButtonTheme), attrs)
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,11 @@ package com.moyerun.moyeorun_android.views

import android.content.Context
import android.util.AttributeSet
import androidx.appcompat.content.res.AppCompatResources
import android.view.ContextThemeWrapper
import androidx.appcompat.widget.AppCompatButton
import androidx.core.content.ContextCompat
import com.moyerun.moyeorun_android.R

class RoundButton constructor(
context: Context,
attributeSet: AttributeSet
) : AppCompatButton(context, attributeSet) {

init {
this.background = AppCompatResources.getDrawable(context, R.drawable.shape_round_botton)
this.setTextColor(ContextCompat.getColor(context, R.color.main_white))
this.textSize = 18F
}
}
attrs: AttributeSet? = null
) : AppCompatButton(ContextThemeWrapper(context, R.style.RoundButtonTheme), attrs)
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true">
<shape android:shape="rectangle">
<item android:state_enabled="true" android:state_pressed="false">
<shape android:shape="rectangle" >
<solid android:color="@color/main_blue"/>
</shape>
</item>
<item android:state_enabled="true" android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="@color/button_pressed_true"/>
</shape>
</item>
<item android:state_enabled="false">
<shape android:shape="rectangle">
<solid android:color="@color/button_enable_false"/>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/selector_rectangle_button_text.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="@color/main_white" />
<item android:state_enabled="false" android:color="@color/button_text_enable_false"/>
<item android:color="@color/main_white" />
</selector>
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true">
<item android:state_enabled="true" android:state_pressed="false">
<shape android:shape="rectangle">
<solid android:color="@color/main_blue"/>
<corners android:radius="4dp"/>
</shape>
</item>
<item android:state_enabled="true" android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="@color/button_pressed_true"/>
<corners android:radius="4dp"/>
</shape>
</item>
<item android:state_enabled="false">
<shape android:shape="rectangle">
<solid android:color="@color/button_enable_false"/>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/selector_round_button_text.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="@color/main_white" />
<item android:state_enabled="false" android:color="@color/button_text_enable_false"/>
<item android:color="@color/main_white" />
</selector>
7 changes: 0 additions & 7 deletions app/src/main/res/values/attrs.xml

This file was deleted.

2 changes: 2 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
<color name="main_light_blue">#EEF4FF</color>

<!-- extra colors -->
<color name="button_pressed_true">#0047D0</color>
<color name="button_enable_false">#C4C4C4</color>
<color name="button_text_enable_false">#828282</color>
</resources>
20 changes: 20 additions & 0 deletions app/src/main/res/values/styles_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="RectangleButtonTheme">
<item name="buttonStyle">@style/RectangleButton</item>
</style>
<style name="RectangleButton" parent="Widget.AppCompat.Button">
<item name="android:background">@drawable/selector_rectangle_button</item>
<item name="android:textSize">21dp</item>
<item name="android:textColor">@drawable/selector_rectangle_button_text</item>
</style>

<style name="RoundButtonTheme">
<item name="buttonStyle">@style/RoundButton</item>
</style>
<style name="RoundButton" parent="Widget.AppCompat.Button">
<item name="android:background">@drawable/selector_round_button</item>
<item name="android:textSize">21dp</item>
<item name="android:textColor">@drawable/selector_round_button_text</item>
</style>
</resources>

0 comments on commit 0a84c3c

Please sign in to comment.