【问题标题】:Android highlight selected fragmentAndroid 高亮选中片段
【发布时间】:2015-11-30 12:26:01
【问题描述】:

大家好,我正在创建导航抽屉,导航抽屉已完成,但我需要突出显示选定的项目。我对其他教程感到困惑,需要帮助。

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"  />

【问题讨论】:

    标签: android android-fragments material-design


    【解决方案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);
    

    【讨论】:

    • 我有一个错误,因为我使用的 Fragmentdrawer 不是列表视图
    猜你喜欢
    • 2014-10-24
    • 2013-08-07
    • 2019-06-26
    • 2013-11-04
    • 2023-03-05
    • 2015-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多