如何更改导航抽屉布局中的设置图标?

时间:2018-01-02 13:43:06

标签: android navigation

我不知道如何改变红圈。

image

我认为只需更改此图标

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
android:icon="@drawable/icon_logout"
app:showAsAction="never" />
</menu>

但是..它不是......所以我怎么能改变呢?

这是我的onCreate ..

 protected void onCreate(Bundle paramBundle) {
    super.onCreate(paramBundle);
    setContentView(R.layout.activity_base);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar((Toolbar) toolbar);
    mContext = this;
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);

    drawer.setDrawerListener((DrawerLayout.DrawerListener) toggle);
    toggle.syncState();
    setTitle("For Good Posture");

    setNaviMenu();

    displaySelectedScreen(R.id.nav_home);
    setDisplaySize();
}

已更新

这是我的style.xml

<resources>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

<style name="MyMaterialTheme" parent="MyMaterialTheme.Base">

</style>

<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">#fff</item>
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>

<style name="DrawerArrowStyle" parent="@style/Widget.AppCompat.DrawerArrowToggle">
    <item name="spinBars">true</item>
    <item name="color">@android:color/black</item>
</style>

<style name="ToolBarStyle" parent="">
    <item name="android:elevation">@dimen/toolbar_elevation</item>
    <item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
    <item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<dimen name="toolbar_elevation">4dp</dimen>

<style name="RadioButtonStyle" parent="@android:style/Widget.CompoundButton">
    <item name="android:background">@drawable/radiobutton_selector</item>
    <item name="android:button">@null</item>
</style>

<style name="DialogNoTitleBar" parent="android:style/Theme.Dialog">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:backgroundDimEnabled">true</item>
</style>

<style name="TabLayoutTextStyle">
    <item name="android:textSize">16sp</item>
    <item name="android:textStyle">bold</item>
</style>

<style name="ButtonSubmit">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">match_parent</item>
    <item name="android:background">@drawable/style_btn_login</item>
    <item name="android:paddingTop">5dp</item>
    <item name="android:paddingBottom">5dp</item>
    <item name="android:textSize">17dp</item>
    <item name="android:textStyle">bold</item>
    <item name="android:textColor">@color/white</item>
</style>

<style name="MyTheme" parent="android:style/Theme.Holo.Light">
    <item name="android:actionOverflowButtonStyle">@style/ActionButtonOverflowStyle</item>
</style>
<style name="ActionButtonOverflowStyle" parent="android:style/Widget.Holo.ActionButton.Overflow">
    <item name="android:src">@drawable/icon_logout</item>
</style>

</resources>

更新

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.cheon.android.forgoodposture_180102"
android:versionCode="6"
android:versionName="1.6">

<uses-sdk
    android:minSdkVersion="26"
    android:targetSdkVersion="26" />

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/app_icon_full"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".Login.IntroActivity"
        android:theme="@style/Theme.AppCompat.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".AppInformation.AppInfoActivity" />
    <activity android:name=".Signup.SignupActivity" />
    <activity
        android:name=".SearchPassowrd.SearchPasswordActivity"
        android:theme="@style/MyMaterialTheme" />
    <activity
        android:name=".Login.LoginActivity"
        android:theme="@style/MyMaterialTheme" />
    <activity android:name=".Signup.BeforeConfirmActivity" />
    <activity
        android:name=".Main.BaseActivity"
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:label="@string/title_activity_base"
        android:theme="@style/AppTheme"
        android:windowSoftInputMode="adjustPan|adjustNothing" />
    <activity
        android:name=".WorkoutDiary.SatisfactionActivity"
        android:theme="@style/DialogNoTitleBar" />
    <activity
        android:name=".WorkoutDiary.ImplementActivity"
        android:theme="@style/DialogNoTitleBar" />

    <receiver android:name=".WorkoutDiary.AlarmReceiver" />
</application>
</manifest>

2 个答案:

答案 0 :(得分:1)

您遇到的问题是因为它不是设置按钮,而是溢出按钮。这就是设置图标不起作用的原因。

要更改这三个点,您应该为您的活动主题指定正确的 android:actionOverflowButtonStyle 样式:

<style name="MyTheme" parent="android:style/Theme.Holo.Light">
     <item name="android:actionOverflowButtonStyle">@style/ActionButtonOverflowStyle</item>
</style>

<style name="ActionButtonOverflowStyle" parent="android:style/Widget.Holo.ActionButton.Overflow">
    <item name="android:src">@drawable/YOUR_DRAWABLE_IMAGE</item>
</style>

我现在的结果是:

enter image description here

答案 1 :(得分:0)

您可以使用自定义菜单项视图,也可以参见下面的链接。

https://stablekernel.com/using-custom-views-as-menu-items/

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto">

    <item
        android:id="@+id/activity_main_alerts_menu_item"
        android:title="Alerts"
        app:actionLayout="@layout/view_alertsbadge" <!-- important part -->
        app:showAsAction="ifRoom"/>

    <item
        android:id="@+id/activity_main_update_menu_item"
        android:icon="@drawable/ic_refresh_white_24dp"
        android:title="Update"
        app:showAsAction="ifRoom"/>

</menu>