0
<menu
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/action_save"
        android:title="@string/action_save"
        android:icon="@drawable/ic_action_save"
        android:orderInCategory="100"
        app:showAsAction="always"
        app:actionLayout="@layout/layout_menu_save"/>
</menu> 

This is my function code

  fun isAdvanceSearchButtonEnabled(bool: Boolean) {

        menu?.getItem(0)?.setEnabled(bool)

        (menu?.getItem(0) as TextView).setTextColor(Color.parseColor("#000000"))

    }

    override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) {
        inflater?.inflate(R.menu.menu_cs_search_advance, menu)
        this.menu = menu
        super.onCreateOptionsMenu(menu, inflater)
    }

    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        when (item?.itemId) {
            R.id.action_advance_search_query -> {

            }
        }
        return super.onOptionsItemSelected(item)
    }

I want to change Menu item color on based of condition but I am not able to get I will case menu item as textview or how to change menu item text color I tried as type cast but it show null can not cast as text view please suggest me how I will change menu item text color problematically in Android

7
  • But icons do not have text. Commented Feb 20, 2018 at 5:54
  • i dont have icon its only text can u please tell me how change text color @meditat Commented Feb 20, 2018 at 5:57
  • you should check at debug what instance is null, maybe menu doesn't get initialized and it's null all the way Commented Feb 20, 2018 at 8:19
  • you want to change text color of menu with xml or kotlin? Commented Feb 20, 2018 at 9:09
  • yes yes @willywijaya Commented Feb 20, 2018 at 9:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.