• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Set popupmenu background color

My codes.
MainActivity.java:
Code:
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate your main_menu into the menu
        getMenuInflater().inflate(R.menu.menu_main, menu);

        // Find the menuItem to add your SubMenu
        MenuItem myMenuItem = menu.findItem(R.id.Hoofdmenu);

        // Inflating the sub_menu menu this way, will add its menu items
        // to the empty SubMenu you created in the xml
        getMenuInflater().inflate(R.menu.submenu_main, myMenuItem.getSubMenu());
        return true;
    }
        public void sendMessage(View view)
        {
            Intent intent = new Intent(this, DisplayMessageActivity.class);
            EditText editText = (EditText) findViewById(R.id.edit_message);
            String message = editText.getText().toString();
            if(editText.getText().toString().equals("bart")){
            startActivity(intent);
        }
            else {
                Toast.makeText(getApplicationContext(), "Fout.",
                        Toast.LENGTH_LONG).show();
            }
    }
}
Activity_main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText android:id="@+id/edit_message"
    android:layout_height="wrap_content"
    android:hint="@string/edit_message"
    android:layout_weight="1"
    android:layout_width="0dp"/>
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_send"
    android:onClick="sendMessage" />
</LinearLayout>
menu_main.xml
Code:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.example.bart.myapplication.MainActivity"
    android:background="@drawable/magenta2"
    android:layout_width="wrap_content"
    android:id="@+id/popup"
    android:layout_height="wrap_content"
    android:theme="@style/Popup">
    <item android:title="Hoofdmenu"
        android:id="@+id/Hoofdmenu">
        <!-- A empty SubMenu -->
        <menu></menu>
    </item>
</menu>
styles.xml
Code:
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    <item name="actionOverflowMenuStyle">@style/OverflowMenu</item>
</style>
    <style name="OverflowMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
        <!-- Required for pre-Lollipop. -->
        <item name="overlapAnchor">false</item>
    </style>

</resources>
I want to change the background color of Menu Main. Can anyone give me the solution or an example?
 
Back
Top Bottom