How can I set the color and size of the text? (I use the selector)
-
02-07-2021 - |
سؤال
my source selector
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_pressed" android:state_focused="true" android:state_pressed="true"></item>
<item android:drawable="@drawable/button_selected" android:state_activated="true"></item>
<item android:drawable="@drawable/button_normal"></item>
</selector>
an example of how I set the style - button_normal.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#F1F4F2" />
<corners
android:bottomLeftRadius="7dip"
android:topLeftRadius="7dip" />
</shape>
how in the "shape" set the size and color of the text? maybe there is another way to set the size and color for the selector?
المحلول
This way is just for the background of the button.
You should use another selector on the
android:textColor="@color/your_color_selector"
and put this file under the res/color folder
Here is an example:
your_color_selector.xml
<item android:state_pressed="true" android:color="@android:color/blue"/>
<item android:state_enabled="true" android:state_selected="true" android:color="@android:color/white"/>
<item android:color="@android:color/black"/>
نصائح أخرى
You can create a style, and that define the text size, color, and drawable (also much more).
You can do something like that:
Create a file named style.xml in the values folder:
<style name="button_style">
<item name="android:textColor">#ffffff</item>
<item name="android:textSize">18dp</item>
<item name="android:background">@drawable/your_selector</item>
</style>
And then go to your Button declaration and define the style of a button for example :
<Button
style="@style/button_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"/>
لا تنتمي إلى StackOverflow