我想将一个颜色选择器分配给一个LinearLayout的扩展类,所以我认为它就像我们谈论linearLayout一样。LinearLayout上的选择器颜色
我按照this后的说明,回答了关于形状的说法。
现在我已经绘项目文件夹3 XML:
normal.xml文件
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#ffffffff" />
</shape>
pressed.xml文件
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#00000000" />
</shape>
最后,bg.xml文件
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/pressed" />
<item android:state_focused="true" android:drawable="@drawable/pressed" />
<item android:state_selected="true" android:drawable="@drawable/pressed" />
<item android:drawable="@drawable/normal" />
</selector>
我正在访问这适用于以下方式:
Drawable d = getResources().getDrawable(context.getResources().getIdentifier("mypackageuri.tProject:drawable/bg", null, null));
view.setBackgroundDrawable(d);
“正常”状态的细末,用颜色设置为“normal.xml”,但没有办法跟其他的人,我按我的观点,并没有任何反应,这不是改变颜色以任何方式......
我不能看见我做错了什么......
谢谢
可能需要粘贴布局XML – azharb
哇这必须得到一个绘制资源的最迂回的方式。 。代替 'getResources()getDrawable(context.getResources()则getIdentifier( “mypackageuri.tProject:可拉伸/ BG”,NULL,NULL));' 尝试 'getResources()getDrawable(R。 drawable.bg);'。除非我错过了一些东西。 – dmon
@dmon好点,生病也试试!谢谢!! – Deitools