我想制作一个没有操作栏的弹出菜单。它工作正常,但只显示一个黑色方块,只有在触摸时才能看到这些项目。 我尝试了很多不同的代码,但没有任何效果......有什么建议吗?`
代码:
@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>
和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>
答案 0 :(得分:0)
在您的活动的布局文件中,在工具栏中检查此属性
// button click
$( form ).on( 'click', 'button', function () {
// set preview
setPreview( $( this ).data( 'preview' ) );
} );
答案 1 :(得分:0)
好的,我刚刚发现问题(我只是说,对于未来类似的问题......):
setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);
我删除了这个,现在一切正常!希望这会有助于他人! :)