Android突出显示所选片段

时间:2015-11-30 12:26:02

标签: android android-fragments material-design

大家好我创建导航抽屉,导航抽屉已完成,但我需要突出显示所选项目。我很困惑,其他教程需要帮助。

Need to highlight selected

这是导航抽屉的xml:

<fragment
    android:id="@+id/fragment_navigation_drawer"
    android:name="test.usmaan.alam.urdudictionarytest.Activities.FragmentDrawer"
    android:layout_width="@dimen/nav_drawer_width"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:layout="@layout/fragment_navigation_drawer"
    tools:layout="@layout/fragment_navigation_drawer"  />

1 个答案:

答案 0 :(得分:1)

创建导航抽屉项目背景的背景,如下所示

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/bg_normal" android:state_activated="false"/>
<item android:drawable="@drawable/pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/bg_pressed" android:state_activated="true"/>

</selector>
在点击项目

时添加以下部分代码
drawerList.setItemChecked(position, true);
drawerList.setSelection(position);