[英]Navigation drawer: unable to show the back icon instead of hamburger icon on the toolbar in the children activities
I am using the DrawerLayout with the v7 Toolbar, and I want to show the hamburger icon in the main activity, and the back icon in the children activities.我将 DrawerLayout 与 v7 工具栏一起使用,我想在主活动中显示汉堡包图标,在儿童活动中显示后退图标。
I am not able to do that, the hamburger icon is always shown, also in the children activities.我不能这样做,汉堡包图标总是显示,也在儿童活动中。
I already searched on so without success (if I lost some usefull questions I apologize).我已经搜索过了,但没有成功(如果我丢失了一些有用的问题,我深表歉意)。
This is the Android manifest:这是Android清单:
<activity android:name=".activities.MainActivity"></activity>
<activity
android:name=".activities.BuyActivity"
android:windowSoftInputMode="adjustResize"
android:parentActivityName=".activities.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.MainActivity" />
</activity>
This is the activity code (the BaseActivity is the superclass for the parent and children activities):这是活动代码(BaseActivity 是父子活动的超类):
public class BaseActivity extends AppCompatActivity implements NavigationDrawerFragment.NavigationDrawerCallbacks {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_buy);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.app_name, R.string.app_name);
drawerLayout.addDrawerListener(actionBarDrawerToggle);
getSupportActionBar().setDisplayShowTitleEnabled(false);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
// Set up the drawer.
mNavigationDrawerFragment.setUp(
R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
}
}
This is the part of the layout of the toolbar:这是工具栏布局的一部分:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:background="?attr/colorPrimary">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txtTitle"
android:textColor="@android:color/white"
android:text="@string/title_buy"
android:textAppearance="@android:style/TextAppearance.Large" />
<ImageView
android:layout_width="@dimen/toolbar_image"
android:layout_height="@dimen/toolbar_image"
android:src="@drawable/done"
android:background="@drawable/bg_border_white_l"
android:layout_marginRight="@dimen/toolbar_margin_right"
android:layout_marginEnd="@dimen/toolbar_margin_right"
android:contentDescription="@string/app_name"
android:layout_gravity="end"
android:id="@+id/imgDone" />
</android.support.v7.widget.Toolbar>
I tried:我试过:
I don't know what I am doing wrong.我不知道我做错了什么。
In child activities you should not add ActionBarDrawerToggle
, as this is what sets a hamburger icon.在子活动中,您不应添加ActionBarDrawerToggle
,因为这是设置汉堡图标的原因。 Move the ActionBarDrawerToggle
to the main activity instead.将ActionBarDrawerToggle
移动到主活动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.