簡體   English   中英

如何在導航欄抽屜上的菜單中突出顯示所選項目

[英]how to highlight the selected item in the menu on the navigation bar drawer

我已經創建了一個帶有菜單的導航抽屜欄,但是當我檢查抽屜欄時,我想突出顯示並禁用菜單欄上的所選項目。

我怎樣才能做到這一點 ?

當我單擊菜單上的項目時,我也沒有看到單擊動畫

請幫忙

謝謝。

這是我使用的代碼

mRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
        @Override
        public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {
            View child = recyclerView.findChildViewUnder(motionEvent.getX(),motionEvent.getY());



            if(child!=null && mGestureDetector.onTouchEvent(motionEvent)){
                Drawer.closeDrawers();
                Toast.makeText(MainActivity.this, "The Item Clicked is: " + recyclerView.getChildPosition(child), Toast.LENGTH_SHORT).show();


                int pos = recyclerView.getChildPosition(child);

                if(pos== 1){
                    Intent intent = new Intent(getApplicationContext(),About.class);
                    startActivity(intent);
                }

                return true;

            }

            return false;
        }

        @Override
        public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {

        }

        @Override
        public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {

        }
    });

RecyclerView不像ListView那樣處理項目選擇或狀態。 相反,您必須在視圖持有者中手動處理此問題。

您可以做的第一件事是在您的ViewHolder構造函數中將項目視圖聲明為可點擊的:

公共ViewHolder(查看itemView){超級(itemView);

// Make this view clickable
itemView.setClickable(true);

// ...

}

http://www.grokkingandroid.com/statelistdrawables-for-recyclerview-selection/

暫無
暫無

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

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