【发布时间】:2018-09-30 17:32:30
【问题描述】:
所以,我有带有 FrameLayout 的 Activity,活动布局的代码
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<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>
<include layout="@layout/content_main"/>
当我要去不同的片段时,我需要更改工具栏。
我需要设置不同的文本,显示返回箭头,删除返回箭头,以及显示/删除菜单右上角的三个点。
我在 Activity 中有下一个代码
@Override
public void onCreate(Bundle savedInstanceState) {
...
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
...
}
以及我班级中的下一个方法
public void setTextTabBar(String title) {
getSupportActionBar().show();
getSupportActionBar().setTitle(title);
}
public void setTabBarFragment() {
getSupportActionBar().show();
getSupportActionBar().setTitle(getString(R.string.about_app_title));
toolbar.setNavigationIcon(android.support.v7.appcompat.R.drawable.abc_ic_ab_back_material);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
setFragment(fragmentMain);
}
});
}
这是正确的方法吗?我正在编码到 android 8+。
另外我需要添加菜单,去掉后退箭头,如何实现?
【问题讨论】: