1
请在将此标记为“重复”之前阅读!在活动对话框中添加OptionMenu
我需要在我的活动对话框中添加一个Option Menu
或图标,但我在这里呆了两天。 Option Menu
没有显示。我使用自定义主题来制作自定义活动对话框。我也使用了一个自定义标题。在这里我的代码片段,以明确:
的manifest.xml
<activity
android:name=".ModalActivity"
android:theme="@style/Theme.Custom.AlertDialog" />
style.xml
<style name="Theme.Custom.AlertDialog" parent="Theme.AppCompat">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowNoTitle">false</item>
</style>
ModalActivity.java
public class ModalActivity extends AppCompatActivity implements View.OnClickListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(getWindow().FEATURE_CUSTOM_TITLE);
setContentView(R.layout.modal_activity);
DisplayMetrics metrics = getResources().getDisplayMetrics();
int screenWidth = (int) (metrics.widthPixels * 0.90);
getWindow().setLayout(screenWidth, ViewGroup.LayoutParams.WRAP_CONTENT);
getWindow().setBackgroundDrawableResource(R.color.colorRedTheme);
this.setFinishOnTouchOutside(false);
getWindow().setFeatureInt(getWindow().FEATURE_CUSTOM_TITLE, R.layout.title_dialog_editor);
final TextView customTitle = (TextView) findViewById(R.id.title_text_dialog_editor);
if (customTitle != null) {
customTitle.setText("Modal Activity");
customTitle.setTextSize(20f);
customTitle.setPadding(5, 5, 5, 0);
customTitle.setBackgroundColor(Color.parseColor("#BA0B0B"));
customTitle.setTextColor(Color.WHITE);
}
setTitle("");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.refresh:
return true;
}
return super.onOptionsItemSelected(item);
}
的问题是菜单不显示。我在这里搜索关于我的案例,但没有解决方案。任何建议和帮助将感谢。
编辑: 下面的图片中,我需要补充一些Option Menu
在我的标题,但Option Menu
不表明
你得到任何错误?如果是,请附上您的logcat太 – Mandy8055
@ Mandy8055没有,没有错误,但在选项菜单中是不是在我的工具栏显示。我没有任何想法,因为我的正常活动(不是活动对话框)使用相同的代码和选项菜单是显示 –
在这种情况下,请您附上'optionsMenu'需要显示的应用程序的屏幕截图!!!它会帮我帮助你... – Mandy8055