当按钮有涟漪效应时,更改按钮属性中按钮的颜色(出现)
我想更改按钮的颜色。我们说:蓝色。我们如何在ripple.xml
文件中添加按钮的颜色,这实际上是按钮的属性?从下面的代码中,按钮的颜色是透明的。当按钮有涟漪效应时,更改按钮属性中按钮的颜色(出现)
在content_main.xml按钮
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ripple"
android:text="Hello World!" />
ripple.xml
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="#f816a463"
tools:targetApi="lollipop">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#f816a463" />
</shape>
</item>
</ripple>
EDIT1
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="#16a463"
tools:targetApi="lollipop">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#16a463" />
</shape>
</item>
</ripple>
ripple_drawabl e.xml //这个地方绘制-V21夹
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item android:id="@android:id/mask">
<shape android:shape="oval">
<solid android:color="@color/your_color" />
</shape>
</item>
</ripple>
注:根据您的问题是,你想改变颜色,就在Android 5.0及以上
它不会更改button的colorrrrrrrrrrrrrr。 – Humty
你正在测试哪个版本的android? – SaravInfern
我想改变按钮的颜色。当我点击按钮时,它会变成灰色的颜色。但按钮仍然是白色的。我改变了按钮的颜色。 – Humty
连锁反应只会工作? 只是改变<solid android:color="#f816a463"
的价值ripple.xml
F816A463
颜色F8
的前两位数字是指不透明度,如果你想纯色,请删除前两个数字,例如:#ff1122
我希望认为这是不正常的,因为它是在他的问题(但我可以感到惊讶......) – AxelH
问题是android:id="@android:id/mask"
。我认为它提供了android的自定义值。
试试这个.....
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item android:drawable="@drawable/button_normal" />
</ripple>
输出: -
您必须使用选择这个动画....
anim.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/ripple"/>
<item android:drawable="@drawable/button_normal"/>
</selector>
并设置默认的颜色在button_normal.xml
.....
,并设置你的按钮背景anim.xml
.....
注: - 纹波正在API级别21以上 .......
,如果你的目的是只设置按钮的背景颜色onCreate
方法试试这个初始化你的按钮
Button yourBtn = (Button) findViewById(R.id.yout_btn_id);
yourBtn.setBackgroundColor(getResources().getColor(R.color.your_color));
后,在你color.xml
文件中定义your_color
值的资源下值夹
使用'#16a463'六位数的颜色。 8位数字包含透明颜色的颜色。 – sushildlh
@sushildlh在哪里添加背景颜色? – Humty
in the ripple.xml'android:color =“#16a463”'这里使用的蓝色代码只有6位数...... – sushildlh