我做了一个按钮,改变了不同状态下的背景,这样:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/btn_location_pressed" /> <!-- pressed -->
<item android:state_focused="true" android:drawable="@drawable/btn_location_pressed"/> <!-- focused -->
<item android:drawable="@drawable/btn_location"/> <!-- default -->
这里的问题是我也试图改变textColor,就像我对drawable一样,但我无法做到 . 我已经尝试过android:textColor和android:color但第一个不起作用,而秒数改变了我的背景 .
下一个代码是我布局的一部分 . 关于文本颜色,它仅适用于正常状态文本颜色,因此在按下时不会将其更改为白色
<Button android:id="@+id/location_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:background="@drawable/location"
android:textSize="15sp"
android:textColor="@color/location_color"
android:textColorHighlight="#FFFFFF"
/>
有人有线索吗?
4 回答
为您的按钮创建有状态颜色,就像您为背景所做的那样,例如:
将xml放在res / drawable文件夹中的文件中,即res / drawable / button_text_color.xml . 然后将drawable设置为文本颜色:
另一种方法是在你的课堂上:
确定非常简单首先转到1. res-valuse并打开colors.xml 2.copy定义文本1例如#FF4081并更改名称例如我改为白色并更改其值例如我改为#FFFFFF for像这样的白色值
然后在你的按钮里面添加这一行
ok b3是我的按钮的名称,所以如果你使用白色,如果你改变不同的颜色,然后将白色改为你的颜色的名称,但是首先你用颜色定义了这个颜色的名称 . 像我在pont 2中解释的xml
Changing text color of button
因为此方法现已弃用
我使用以下内容: