如何在动作栏中替换溢出和导航抽屉?

时间:2018-02-15 10:18:27

标签: java android user-interface layout

大家好,我搜索了很多,但我什么都没有,我怎么能取代这两个 我的动作栏中的图标?非常感谢

我已经尝试但结果不合适。

    <android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end" // here i tried change the gravity but didnt work
    android:layout_margin="@dimen/fab_margin"
    app:srcCompat="@android:drawable/ic_dialog_email" />

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

enter image description here

2 个答案:

答案 0 :(得分:1)

试试这个

Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);
toolbar.setNavigationIcon(R.drawable.your_icon);

Drawable drawable = context.getDrawable(getApplicationContext(),R.drawable.your_overflowicon);
toolbar.setOverflowIcon(drawable);

答案 1 :(得分:0)

AndroidManifest.xml中添加如下

<application android:supportsRtl="true">

您的代码看起来像

  <application
        android:name=".app.AppController"
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true" //here change
        android:theme="@style/AppTheme">
        <activity android:name=".LoginActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

然后

在您的活动的onCreate()方法

中添加以下行
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);