片段工具栏后退按钮未显示

时间:2017-11-22 21:29:19

标签: android android-fragments

我设置了我的自定义工具栏并将“setHomeButtonEnabled”和“setDisplayHomeAsUpEnabled”设置为true,并且由于某些奇怪的原因工具栏显示但不是实际的后退按钮。我已经尝试设置一个自定义图标,并在更改片段时设置工具栏,并且工具栏始终显示,但是后退部分从不显示。可能是因为我没有被称为注册活动吗?

public class RegisterActivity extends BaseActivity {


@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.activity_register);
    ButterKnife.bind(this);

    Toolbar toolbar = findViewById(R.id.my_toolbar);
    toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material);

    setSupportActionBar(toolbar);
    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

片段的活动

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@color/ghostWhiteColor"
    android:fitsSystemWindows="true"

    tools:context="com.vice.de.flu.activity.RegisterActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/my_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/holo_blue_light"/>
    </android.support.design.widget.AppBarLayout>


    <!--wizard>-->
    <FrameLayout
        android:id="@+id/fragment_register"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

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

我的清单

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".activity.MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".activity.RegisterActivity"
        android:windowSoftInputMode="adjustPan|adjustResize">

    </activity>
</application>

1 个答案:

答案 0 :(得分:0)

<android.support.v7.widget.Toolbar
   android:id="@+id/my_toolbar"
   android:layout_width="match_parent"
   android:layout_height="?attr/actionBarSize"
   android:background="@color/holo_blue_light"
   app:navigationIcon="@drawable/back_navigation_icon" />
相关问题