How to change popupmenu background

  • Replies:0
Bart de Kinkelaar
  • Forum posts: 1

Oct 31, 2016, 9:31:17 AM via Website

My codes.
MainActivity.java:
Code (Text):

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 (Text):


xmlns:android="..."
xmlns:tools="..."
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="wrap_content"
android:hint="@string/edit_message"
android:layout_weight="1"
android:layout_width="0dp"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="sendMessage" />

styles.xml
Code (Text):

<!-- 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>




false


i have also a menu page, but this forum doesn't show the code of the menu_main page nice.
I want to change the background color of Menu Main. Can anyone give me the solution or an example?

— modified on Oct 31, 2016, 9:34:04 AM

Reply