我想稍微更改标准Android按钮的颜色,以便更好地匹配客户的品牌.
到目前为止,我发现这样做的最好方法是将Button'drawable'改为drawable,位于res/drawable/red_button.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/red_button_pressed" />
<item android:state_focused="true" android:drawable="@drawable/red_button_focus" />
<item android:drawable="@drawable/red_button_rest" />
</selector>
Run Code Online (Sandbox Code Playgroud)
但这样做需要我居然为每一个按钮,我想自定义三种不同的可绘制(一个用于按钮在休息,一个集中的时候,和一个按下时).这似乎比我需要的更复杂,更干燥.
我真正想做的就是对按钮应用某种颜色转换.是否有更简单的方法来改变按钮的颜色而不是我正在做的事情?
我在ICS应用程序中使用带有holo.light主题的标准Switch控件.
我想将切换按钮的突出显示或状态颜色从标准浅蓝色更改为绿色.
这应该很容易,但我似乎无法弄清楚如何做到这一点.
我一直在阅读一个教程,该教程解释了如何使用具有不同状态的按钮的背景但它似乎不起作用:S
这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/boutonn" android:state_window_focused="false"/>
<item android:drawable="@drawable/boutonnpousse" android:state_pressed="true"/>
<item android:drawable="@drawable/boutonnpousse" android:state_focused="true"/>
<item android:drawable="@drawable/boutonn" android:state_focused="false"
android:state_pressed="false" />
</selector>
Run Code Online (Sandbox Code Playgroud)
这是我放在我的drawable文件夹中的xml代码,这里是使用这些按钮的活动的xml的一部分:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/backgrounddd"
android:orientation="vertical" >
<Button
android:id="@+id/bNoteRemind"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:background="@drawable/imagebutton1" />
...
Run Code Online (Sandbox Code Playgroud)
这是java类:
public class MenuPrincipal extends Activity {
Button NoteRemind;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//on lui associe le layout menuprincipal.xml
setContentView(R.layout.menuprincipal);
NoteRemind = (Button) findViewById(R.id.bNoteRemind);
// Si on choisit de rédiger une …Run Code Online (Sandbox Code Playgroud) 大家好,我想使用切换按钮,但具有不同的指示器颜色(如绿色或红色),如何更改指示器的颜色。