1

这是我的开始活动。它以编程方式工作正常。

我面临的唯一问题是,当硬件菜单键调用时,溢出菜单是深色主题。

我已在此示例中提供了所有基本的代码行。

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的溢出菜单图标调用时的样子

这是按下 Hardware Menu 键时我的 App OverFlow-Menu 的外观

4

1 回答 1

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>

实现其中之一以更改通过图标(前代码)或硬件键(后代码)调用的溢出菜单的颜色。

于 2017-07-27T04:39:54.387 回答