Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了安卓 – 当导航抽屉打开时,工具栏按钮不响应触摸大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用appcompat v7库处理我的应用程序的材料设计版本,我遇到了导航抽屉的问题.打开时,材料设计工具栏中的按钮将停止运行 – 导航抽屉外的任何触摸都会关闭抽屉.以下是我的意思的gif

the gif http://images.rymate.co.uk/images/83JXi1X.png

这是我用于活动的xml布局:

<android.support.v4.widget.DrawerLayout xmlns:android="http://scheR_784_11845@as.android.com/apk/res/android"
    xmlns:app="http://scheR_784_11845@as.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- The main content view -->
    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.Toolbar
            android:id="@+id/action_toolbar"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:minHeight="?attr/actionBarSize"
            android:BACkground="?attr/colorPriMary"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            android:elevation="4dp"
            />

        <FrameLayout
            android:id="@+id/note_list_container"
            android:layout_marginTop="?attr/actionBarSize"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <net.rymate.noteS.Ui.FloaTingActionButton
            android:id="@+id/fabbutton"
            android:layout_width="72dp"
            android:layout_height="72dp"
            android:layout_gravity="bottom|right"
            android:layout_marginBottom="16dp"
            android:layout_marginRight="16dp" />
    </FrameLayout>
    <!-- The navigation drawer -->
    <LinearLayout
        android:id="@+id/left_drawer"
        android:layout_width="300dp"
        android:layout_marginTop="?attr/actionBarSize"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:orientation="vertical">

        <ListView
            android:id="@+id/cat_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:choiceMode="singleChoice"
            android:divider="@android:color/transparent"
            android:dividerHeight="0dp"
            android:BACkground="?catBACkColour" />
    </LinearLayout>

</android.support.v4.widget.DrawerLayout>

这是onCreate代码初始化抽屉和工具栏.

@Override
protected void onCreate(Bundle savedInstanceStatE) {
    super.onCreate(savedInstanceStatE);

    ROBOTO_LIGHT = Typeface.createFromAsset(this.getAssets(),"Roboto-Light.ttf");
    ROBOTO_LIGHT_ITALICS = Typeface.createFromAsset(this.getAssets(),"Roboto-LightItalic.ttf");

    setContentView(R.layout.activity_notes);

    if (findViewById(R.id.note_container) != null) {
        // The detail container view will be present only in the
        // large-screen layouts (res/values-large and
        // res/values-sw600dp). If this view is present,then the
        // activity should be in two-pane mode.
        mTwoPane = true;

        // In two-pane mode,list items should be given the
        // 'activated' state when touched.
        FragmentManager fm = getSupportFragmentManager();
        //list.setActivateOnItemClick(true);
    }


    if (!mTwoPanE) {
        final FloaTingActionButton mFab = (FloaTingActionButton) findViewById(R.id.fabbutton);
        mFab.init(Color.parseColor("#1e90ff"));
        mFab.setFabDrawable(getresources().getDrawable(R.drawable.ic_action_new));
        mFab.showFab();

        mFab.setOnClickListener(this);

        list = new NotesListFragment(mFab);
    } else {
        list = new NotesListFragment();
    }


    Toolbar toolbar = (Toolbar) findViewById(R.id.action_toolbar);
    setSupportActionBar(toolbar);

    getSupportFragmentManager().begintransaction()
            .replace(R.id.note_list_container,list)
            .commit();

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); // the layout
    mDrawerLinear = (LinearLayout) findViewById(R.id.left_drawer);

    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,GravityCompat.START);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    getSupportActionBar().setHomeButtonEnabled(true);

    mDrawerLayout.setScrimColor(getresources().getColor(android.R.color.transparent));

    mDrawerToggle = new ActionBarDrawerToggle(
            this,/* host Activity */
            mDrawerLayout,/* DrawerLayout object */
            toolbar,/* toolbar */
            R.String.drawer_open,/* "open drawer" description */
            R.String.drawer_close  /* "close drawer" description */
    ) {

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            getSupportActionBar().settitle("Rymate Notes");
            supporTinvalidateOptionsMenu();
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            getSupportActionBar().settitle("Categories");
            supporTinvalidateOptionsMenu();
        }
    };

    // Set the drawer toggle as the DrawerListener
    mDrawerLayout.setDrawerListener(mDrawerTogglE);

    pref = getSharedPreferences("rymatenotesprefs",MODE_PRIVATE);

    mDrawerList = (ListView) findViewById(R.id.cat_list);

    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    mDbHelper = new NotesDbAdapter(this);
    mDbHelper.open();

    if (mDbHelper.fetchAllNotes().getCount() == 0) {
        IntroFragment fragment = new IntroFragment();
        getSupportFragmentManager().begintransaction()
                .replace(R.id.note_list_container,fragment)
                .commit();

    }

    getCategories(); // calls a function which populates the listview

}

有没有办法可以解决这个问题?

解决方法

似乎触摸事件被抽屉的阴影所窃取,即DrawerLayout一直拦截触摸事件,因为工具栏是内容视图的一部分,不像ActionBar位于装饰视图的顶部.

可能的解决方法拦截触摸事件:

如果它介于0(顶部)和工具栏高度(底部)之间,则将事件直接分派给Toolbar对象.否则保持正常行为.

抽屉拨动点击是否相同?

大佬总结

以上是大佬教程为你收集整理的安卓 – 当导航抽屉打开时,工具栏按钮不响应触摸全部内容,希望文章能够帮你解决安卓 – 当导航抽屉打开时,工具栏按钮不响应触摸所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。