Wciśnięty stan przycisku Android
Śledziłem samouczek, który wyjaśnia, jak używać tła dla przycisku z różnymi stanami, ale wydaje się, że nie działa: S
Oto mój kod:
<?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>
To jest kod XML, który umieściłem w moim folderze do rysowania. Oto część xml działania, które używa tych przycisków:
<?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" />
...
A oto klasa 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);
}
}); ....
Przycisk wyświetla się dobrze, ale gdy go naciskam, nie pokazuje wciśniętego obrazu: s Nie rozumiem, co robię źle!
Czy ktoś gdzieś widzi błąd?
Gdzie powinienem umieścić te linie? Umieściłem je w moim przycisku 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" />
Ale teraz moje tło przycisku zmieniło się na wciśnięty obraz bez naciskania go: p i to się nie zmienia