导航抽屉图标在自定义操作栏中不可见?
Navigation Drawer Icon not visible with custom action bar?
我正在尝试将导航抽屉与自定义操作栏一起使用。我的操作栏不包含任何菜单。
我看到导航抽屉图标在抽屉关闭时在操作栏上不可见。即使我在 ActionbarToggle
实现中给出了抽屉图标。抽屉图标在 navigation drawer
打开时出现,但在 navigation drawer
关闭时消失。
活动
public void setCustomActionBar() {
ActionBar actionBar = getActionBar();
actionBar.setCustomView(R.layout.action_bar);
}
NavigationDrawer 片段
getActivity(), /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.drawer, /* nav drawer image to replace 'Up' caret */
R.string.navigation_drawer_open, /* "open drawer" description for accessibility */
R.string.navigation_drawer_close /* "close drawer" description for accessibility */
) {...
如您所见,我在上面提供了抽屉图标。
为什么会发生这种情况,解决方案是什么?
我假设您正在创建自己的自定义 layout.Suppose 我有下面给出的 xml 布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="#cccccc">
<Button
android:layout_width="10dp"
android:id="@+id/drawer_toggle"
android:layout_height="40dp"
android:background="#000000"
android:layout_margin="10dp"
android:layout_gravity="center_vertical|start"/>
</FrameLayout>
</LinearLayout>
那么你可以这样做:
Button toggle = (Button) yourDrawerView.findViewById(R.id.drawer_toggle);
toggle.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
boolean isDrawerOpen = yourDrawerLayoutRefference.isDrawerOpen(yourDrawerLayout);
if(isDrawerOpen){
toggle.closeDrawer(yourDrawerLayout);
}
else{
toggle.openDrawer(yourDrawerLayout);
}
}
});
我正在尝试将导航抽屉与自定义操作栏一起使用。我的操作栏不包含任何菜单。
我看到导航抽屉图标在抽屉关闭时在操作栏上不可见。即使我在 ActionbarToggle
实现中给出了抽屉图标。抽屉图标在 navigation drawer
打开时出现,但在 navigation drawer
关闭时消失。
活动
public void setCustomActionBar() {
ActionBar actionBar = getActionBar();
actionBar.setCustomView(R.layout.action_bar);
}
NavigationDrawer 片段
getActivity(), /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.drawer, /* nav drawer image to replace 'Up' caret */
R.string.navigation_drawer_open, /* "open drawer" description for accessibility */
R.string.navigation_drawer_close /* "close drawer" description for accessibility */
) {...
如您所见,我在上面提供了抽屉图标。 为什么会发生这种情况,解决方案是什么?
我假设您正在创建自己的自定义 layout.Suppose 我有下面给出的 xml 布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="#cccccc">
<Button
android:layout_width="10dp"
android:id="@+id/drawer_toggle"
android:layout_height="40dp"
android:background="#000000"
android:layout_margin="10dp"
android:layout_gravity="center_vertical|start"/>
</FrameLayout>
</LinearLayout>
那么你可以这样做:
Button toggle = (Button) yourDrawerView.findViewById(R.id.drawer_toggle);
toggle.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
boolean isDrawerOpen = yourDrawerLayoutRefference.isDrawerOpen(yourDrawerLayout);
if(isDrawerOpen){
toggle.closeDrawer(yourDrawerLayout);
}
else{
toggle.openDrawer(yourDrawerLayout);
}
}
});