簡體   English   中英

工具欄中漢堡包圖標的可點擊區域不正確

[英]Clickable zone of Hamburger icon in Toolbar is not accurate

我面臨一個自己無法解決的問題。

我無法使用工具欄中的“ 漢堡包”圖標打開導航抽屜 ,但是我發現單擊圖標上方的區域可以將其打開。

這是屏幕截圖:

可點擊區域

在上圖中, 只有單擊紅色區域中的某個位置,我才能打開導航抽屜,否則將不會發生任何事情。

OnCreate:

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

configureToolBar:

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>

您是否有機會使用模擬器? 我發現點擊的准確性非常差。 如果是,那可能就是問題所在。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM