我有点困惑如何解释这一点。让我试试。
我实施了一个导航抽屉。我通过在选择器中使用state_activated来实现所选项目的突出显示背景。
MENU_SELECTOR:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/menu_active" />
<item android:state_activated="true" android:drawable="@drawable/menu_active" />
<item android:drawable="@drawable/menu_normal" />
</selector>
但我希望抽屉中的第3个项目始终保持正常背景。那么,是否可以从此menu_selector中仅排除第3项?
以下是抽屉的代码
public void displayView(int position) {
Fragment fragment = null;
switch (position) {
case 0:
fragment = new MainFragment();
break;
case 1:
fragment = new BookListFragment();
break;
case 2:
openCredit(); // THIS WILL JUST OPEN A DIALOG, HENCE I DON'T WANT IT TO KEEP HIGHLIGHTED BACKGROUND
break;
default:
break;
}
if (fragment != null) {
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.frame_container, fragment, "frag_"+position).commit();
mDrawerList.setItemChecked(position, true);
mDrawerLayout.closeDrawer(drawer);
}
}
LISTVIEW XML
<ListView
android:choiceMode="singleChoice"
android:listSelector="@drawable/menu_selector" />