这是我的开始活动。它以编程方式运行良好。
我面临的唯一问题是,当通过硬件菜单键调用时,OverFlow-Menu会出现黑暗主题。
我已在此示例中提供了所有必要的代码行。
public class StartingActivity extends AppCompatActivity implements LoginActivity_Tab.loginActivityTab_interface {
private static final String LOGIN_URL = "http://rollhack.96.lt/login.php";
private SectionsPagerAdapter mSectionsPagerAdapter;
private ViewPager mViewPager;
private TabLayout tabLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_starting);
includeWidgets();
}
private void includeWidgets() {
///// Tab Layout /////
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.container);
setupViewPager(mViewPager);
tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);
///// ToolBar /////
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
setTitle("Note Pad");
}
///// This method is called for Exiting the App /////
public void exitApp() {
final AlertDialog.Builder exit = new AlertDialog.Builder(StartingActivity.this);
exit.setTitle("Exit Application")
.setMessage("Are you sure you want to Exit the application?")
.setCancelable(true)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
StartingActivity.this.finishAffinity();
}
})
.setNegativeButton(android.R.string.no, null);
exit.create().show();
}
///// This method is called to assign the Key Events /////
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
exitApp();
return true;
}
return super.onKeyUp(keyCode, event);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_starting_activity, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_settings:
return Boolean.parseBoolean(null);
case (R.id.menu_about):
return Boolean.parseBoolean(null);
case (R.id.menu_exit):
exitApp();
return true;
}
return super.onOptionsItemSelected(item);
}
这是ActionBar的溢出菜单图标调用它时的样子
按下硬件菜单键时,这就是我的App OverFlow-Menu的显示方式
答案 0 :(得分:0)
图标溢出菜单
您可以通过在style.xml中添加新样式来更改溢出菜单背景的颜色。
<style name="OverflowMenu"
parent="@android:style/Theme.Holo">
<item name="android:popupMenuStyle">@style/MyOverflowMenu</item>
<item name="android:itemTextAppearance">@style/TextAppearance</item>
</style>
<style name="MyOverflowMenu"
parent="@android:style/Widget.Holo.ListPopupWindow">
<item name="android:popupBackground">@color/your_color</item>
</style>
<style name="TextAppearance">
<item name="android:textColor">@color/your_color</item>
</style>
按硬件密钥覆盖菜单
要更改“硬件”键调用的“溢出”菜单的颜色,请添加其他样式。
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="actionBarPopupTheme">@style/OverflowMenuHardware</item>
</style>
<style name="OverflowMenuHardware" parent="ThemeOverlay.AppCompat.Dark">
<item name="android:textColorSecondary">@color/your_color</item>
<item name="android:colorBackground">@color/your_color</item>
</style>
实现其中任何一个,以更改由图标(以前的代码)或硬件密钥(后面的代码)调用的溢出菜单的颜色。