[英]How to obtain Background color of a button with drawable state?
Here is my drawable state: 这是我的可绘制状态:
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid
android:color="#ffdcd400" />
</shape>
</item>
<item>
<shape>
<solid
android:color="#ffe8e000" />
</shape>
</item>
</selector>
I get the button with this function: 我得到具有此功能的按钮:
public void ir(View v)
{
Button boton_clickeado=(Button)v;
StateListDrawable drawable= (StateListDrawable) v.getBackground();
}
I want to get the background color (state not pressed) "#ffe8e000" programmatically. 我想以编程方式获取背景色(未按状态)“#ffe8e000”。 But I don't know which function use to obtain it.
但是我不知道使用哪个函数来获取它。
尝试这个 ..
int color = Color.TRANSPARENT; StateListDrawable drawable= (StateListDrawable) v.getBackground(); if (drawable instanceof ColorDrawable) color = ((ColorDrawable) drawable).getColor();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.