Ich möchte ein Popup-Menü, ohne Aktionsleiste. Es funktioniert gut, aber nur ein schwarzes Quadrat angezeigt, und die Elemente sind nur bei Berührung sichtbar. Ich habe versucht, viele verschiedene Codes, aber nichts funktionierte .. Irgendwelche Vorschläge bitte `Android PopupMenu keine Elemente angezeigt
Code:?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getSupportActionBar().hide();
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.hide();
}
setContentView(R.layout.activity_test);
settButton = (Button) findViewById(R.id.moresett);
settButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Context wrapper = new ContextThemeWrapper(Test.this, R.style.PopupMenu);
PopupMenu popup = new PopupMenu(wrapper, settButton);
popup.getMenuInflater().inflate(R.menu.sett_menu, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()){
case R.id.curr_sett:
//some code
return true;
case R.id.change_sett:
//some code
return true;
}
return false;
}
});
popup.show();
}
});
` R.menu.sett_menu:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- 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/PopupMenu</item>
</style>
<style name="PopupMenu" parent="@android:style/Widget.PopupMenu">
<item name="android:popupBackground">@android:color/white</item>
</style>
Und menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/curr_sett"
android:title="Current Settings"></item>
<item android:id="@+id/change_sett"
android:title="Change Settings"></item>
Danke für die schnelle Antwort! Ich benutze keine Symbolleiste und Aktionsleiste. Aber ich habe es versucht, aber immer noch das gleiche Ergebnis. – lavou