我一直在下面解释如何使用背景与不同状态的按钮,但它似乎并没有工作教程: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>
这是我一直放在我的绘制文件夹中的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" />
...
这里是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 nouvelle task on va être rediriger sur l'activité NoteReminder
NoteRemind.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
//On créé l'Intent qui va nous permettre d'afficher l'autre Activity
//Mettez le nom de l'Activity dans la quelle vous êtes actuellement pour le premier parametre
v.setPressed(true);
Intent intent = new Intent(MenuPrincipal.this, NoteReminder.class);
//Intent intent = new Intent(MenuPrincipal.this, Teste2.class);
//On démarre l'autre Activity
startActivity(intent);
}
}); ....
该按钮显示不错,但是当我按下它时,它不显示按下的图像:s我不明白我在做什么错误!
有没有人在某处看到错误???
我应该在哪里放这些行?我已经把它们放在我的按钮XML
<Button
android:id="@+id/bNoteRemind"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:background="@drawable/imagebutton1"
android:focusable="true"
android:focusableInTouchMode="true" />
但现在我的按钮背景改为挤压的图像没有我按下它:对,它不会改变
尝试'机器人:可调焦= “真”'和'机器人:focusableInTouchMode = TRUE; – 2012-04-04 21:26:12
[http://stackoverflow.com/questions/11978880 /如何对改变颜色的最肘节按钮] [1] 请参阅本请 [1]:http://stackoverflow.com/问题/ 1 1978880 /如何改变颜色的切换按钮 – haris 2013-12-14 09:45:51