1

As I am clicking on button but it is not showing pressed state. Please help. thanks

my code:

    <item name="android:textColor" >#000</item>
    <item name="android:textSize" >20dp</item>
    <item name="android:background">@drawable/note_icon</item>

</style>

button

    android:id="@+id/createnote"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/Createnote"
    style="@style/Create_text" />

This is my layout and code:

createnote.setOnClickListener(new OnClickListener(){

        public void onClick(View v) {
    // TODO Auto-generated method stub

        //  v.setPressed(true);

    Intent intent = new Intent(getApplicationContext(), Add_Task.class);
    startActivity(intent);
        }
    });
Goo
  • 1,318
  • 1
  • 13
  • 31
Shweta
  • 1,145
  • 5
  • 18
  • 35

1 Answers1

2

Have you created a selector to define comportment when the button is pressed ?

<selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item 
        android:state_enabled="false"
        android:drawable="@drawable/btn_XXXX" />
   <item 
        android:state_pressed="true" 
        android:state_enabled="true"
        android:drawable="@drawable/btn_YYYY" />
   <item 
        android:state_focused="true" 
        android:state_enabled="true"
        android:drawable="@drawable/btn_ZZZZ" />
    <item 
        android:state_enabled="true"
        android:drawable="@drawable/btn_WWWWW" />
</selector>
Goo
  • 1,318
  • 1
  • 13
  • 31
  • Hi, thanks for your answer. where i need to put this Selector in "menu" or "style". – Shweta Jan 17 '13 at 04:57
  • it's a new file res/drawable/new_button.xml, and you can use it with android:background="@drawable/new_button" in your button xml – Goo Jan 17 '13 at 08:46
  • This utilisation is not limited to the background, you can use selector to change the text color (link 1) or the shape (link 2). link1 : http://stackoverflow.com/a/4692899/1720391 - link 2 : http://samir-mangroliya.blogspot.fr/2012/11/android-custom-button-example.html. – Goo Jan 17 '13 at 08:50