How to change the color of the options menu

0

I'm going to change the question again, because the title of the post I think says that what I want to change is the color of the menu , and not the color of the button.

I will not extend much to see if this is better understood

My question is how can I change the color of the options menu and the background color of the options menu?

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    for (int i=0; i<menu.size(); i++) {
        MenuItem mi = menu.getItem(i);
        String title = mi.getTitle().toString();
        Spannable newTitle = new SpannableString(title);
        newTitle.setSpan(new ForegroundColorSpan(Color.BLUE), 0, newTitle.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        mi.setTitle(newTitle);
    }
    return true;
}        

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_opciones, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(android.view.MenuItem item) {

    switch (item.getItemId()){
        case R.id.m_acerca:

            Toast toast = new Toast(getApplicationContext());
            toast.setGravity( Gravity.CENTER,0,0);

            TextView tv = new TextView(MainActivity.this);
            tv.setBackgroundColor( Color.RED);
            tv.setTextColor(Color.YELLOW);
            tv.setTextSize(20);

            Typeface t = Typeface.create("serif", Typeface.BOLD_ITALIC);
            tv.setTypeface(t);
            tv.setPadding(10,10,10,10);
            tv.setText("\"Documentos Versión 1.0\"");
            toast.setView(tv);
            toast.setDuration(Toast.LENGTH_LONG);
            toast.show();

            return true;

        case R.id.m_salir:
            onBackPressed();

        case android.R.id.home:
            onBackPressed();
            return true;
    }

    return super.onOptionsItemSelected(item);
}

Error

Option 2 to change the Color

But I can not change the background color ...

colors.xml

<resources>
<color name="colorPrimary">#0099cc</color>
<color name="colorPrimaryDark">#0099cc</color>
<color name="colorAccent">#FF4081</color>
<color name="colorFondoMenuOpciones">#f2f2f2</color>
<color name="colorTextoMenuOpciones">#ffbb33</color>

styles.xml

<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
     <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <item name="android:popupMenuStyle">@style/MyFondoMenu</item>
    <item name="android:itemTextAppearance">@style/MyTextoMenu</item>

</style>

<!-- color fondo del Menu opciones -->
<style name="MyFondoMenu"
    parent="@android:style/Widget.Holo.ListPopupWindow">
    <item name="android:popupBackground">@color/colorFondoMenuOpciones</item>
</style>
<!-- color Texto del Menu opciones -->
<style name="MyTextoMenu">
    <item name="android:textColor">@color/colorTextoMenuOpciones</item>
</style>

<style name="AppTheme.NoActionBar">
  <item name="windowActionBar">false</item>
  <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

Thank you.

    
asked by SoCu 16.02.2018 в 13:25
source

0 answers