【问题标题】:Clickable zone of Hamburger icon in Toolbar is not accurate工具栏中汉堡包图标的可点击区域不准确
【发布时间】:2018-07-27 03:41:13
【问题描述】:

我面临一个我自己无法解决的问题

我无法使用工具栏中的汉堡图标打开我的导航抽屉,但我发现点击图标上方的区域可以打开它。

这是截图:

在上图中,我可以打开导航抽屉只有如果我点击了红色区域的某个地方,否则什么都不会发生。

创建时:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setupMainViews();
    configureToolBar();
    configureDrawerLayout();
    configureNavigationView();
}

配置工具栏:

private void configureToolBar(){
    this.tbMain = findViewById(R.id.tbMain);
    setSupportActionBar(tbMain);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

configureDrawerLayout:

private void configureDrawerLayout(){
    dlMain = findViewById(R.id.dlMain);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, dlMain, tbMain,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close){
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
        }
    };
    dlMain.addDrawerListener(toggle);
    toggle.syncState();
}

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/dlMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="start"
tools:context=".MainActivity">
    <RelativeLayout
        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:background="@drawable/mainbackground">

        <android.support.v7.widget.Toolbar
            android:id="@+id/tbMain"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:theme="@style/ToolBarStyle"/>

        //other views...

    </RelativeLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/nvSide"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/sideview_header"
        app:menu="@menu/sidemenu_items" />
</android.support.v4.widget.DrawerLayout>

【问题讨论】:

    标签: android android-toolbar


    【解决方案1】:

    您是否正在使用模拟器?我发现它们在点击方面的准确性非常差。如果你是,那可能就是问题所在。

    【讨论】:

    • 我一开始也是这么想的,用手机查了一下,问题还是存在。
    • 你应该看看这个链接:developer.android.com/training/implementing-navigation/… 并确保你设置汉堡菜单的所有步骤都是正确的,可能是汉堡的区域与可点击区域重叠。
    • 对于 onOptionsItemSelected(MenuItem item),我已经尝试过了,但没有成功。我会检查我的步骤是否如您的链接中所述。
    猜你喜欢
    • 2016-03-03
    • 2015-03-24
    • 2016-08-02
    • 2015-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多