0

I am developing an application which consists of button. Here Is My problem,how to set the selected state and unselected state.

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/ox_mnu_dashboard_over" android:state_selected="true"/> <item android:drawable="@drawable/ox_mnu_dashboard_normal"/> </selector> 

I am using this code but not working for me. Here is the xml file:

 <FrameLayout android:id="@+id/tabDashboard" android:layout_width="60dip" android:layout_height="wrap_content" android:layout_marginLeft="2dip" android:layout_weight="1" android:clickable="true" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|center_horizontal" android:focusableInTouchMode="true" android:marqueeRepeatLimit="marquee_forever" android:scrollHorizontally="true" android:singleLine="true" android:text="@string/dashboard" android:textColor="@color/white" android:textSize="12sp" /> <ImageButton android:id="@+id/btnDashboard" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/tab_dashboard" android:clickable="true" /> </FrameLayout> 

1 Answer 1

3

You can set image when click on that imageButton like below code.

int isClicked = 0; image = (ImageButton) findViewById(R.id.image); image.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (isClicked1 == 0) { image.setImageResource(R.drawable.second_image); isClicked1 = 1; } else { image.setImageResource(R.drawable.original_image); isClicked1 = 0; } } });' 
Sign up to request clarification or add additional context in comments.

2 Comments

I need the selected state to be maintained
Then you need to set image when you click on that particular imageButton.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.