Filnik
Filnik

Reputation: 1013

Action Item not clickable in Android ActionBar

I have an ActionBar with this item:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    [...]
    <item android:id="@+id/status_service"
        android:icon="@drawable/network_service"
        android:title="@string/status_service"
        android:showAsAction="always|withText|collapseActionView"/>
</menu>

But I don't want it to be a button. Is a way to set it as non clickable. The layout and appearance is just fine. enabled=false does the job but it changes the color of the text too, I wanted it only to be not clickable.

Thank you!

Upvotes: 3

Views: 7337

Answers (1)

Pradip
Pradip

Reputation: 3177

From code you can use MenuItem setEnabled(false), for details.
or, In your layout:

MenuItem item = menu.findItem(R.id.your_item);
item.setVisible(true);
item.setEnabled(false);

or, In your menu.xml, add the following attribute in item

android:enabled="false"

below code to change the textColor // if you are using menu Item. @Override public boolean onMenuItemSelected(int featureId, MenuItem item) { // change the style here what you want

    return true;
}

As you are using Button the you can do the following.

button = (Button)R.id.buttonId;
  if(button.isenable)
  {
    button.setTextColor(Color.parseColor("#FFBBFF")); //color code
   }

Upvotes: 6

Related Questions