【问题标题】:Fragments toolbar back button not showing片段工具栏后退按钮未显示
【发布时间】:2017-11-22 21:29:18
【问题描述】:

我设置了我的自定义工具栏,并将“setHomeButtonEnabled”和“setDisplayHomeAsUpEnabled”设置为 true,出于某种奇怪的原因,工具栏显示但没有显示实际的后退按钮。我尝试设置自定义图标并在更改片段时设置工具栏 onclick 并且工具栏始终显示但后退箭头从不显示。是不是因为我的 registeractivity 没有被调用?

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>

【问题讨论】:

  • 为什么要扩展 BaseActivity 而不是 AppCompatActivity

标签: android android-fragments


【解决方案1】:
<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" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-10
    • 1970-01-01
    • 2018-01-23
    • 1970-01-01
    • 2015-08-29
    • 1970-01-01
    相关资源
    最近更新 更多