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