【问题标题】:Android Material Design Navigation View -> ItemAndroid Material Design 导航视图 -> 项目
【发布时间】:2015-10-13 09:46:24
【问题描述】:

谁能告诉我如何在android材料设计导航视图中添加一个切换按钮?

从菜单项添加项目

drawer_menu_items.xml

<group android:checkableBehavior="single">

    <item
        android:id="@+id/inbox"
        android:checked="false"
        android:icon="@drawable/ic_inbox_black"
        android:title="@string/inbox_string" />

    <item
        android:id="@+id/starred"
        android:checked="false"
        android:icon="@drawable/ic_star_black"
        android:title="@string/starred_string" />

    <item
        android:id="@+id/sent_mail"
        android:checked="false"
        android:icon="@drawable/ic_send_black"
        android:title="@string/sent_mail_string" />

    <item
        android:id="@+id/drafts"
        android:checked="false"
        android:icon="@drawable/ic_drafts_black"
        android:title="@string/draft_string" />


    <item
        android:id="@+id/allmail"
        android:checked="false"
        android:icon="@drawable/ic_email_black"
        android:title="@string/all_mail_string" />

如何添加项目或如何添加切换按钮,如图所示:

【问题讨论】:

    标签: android xml android-navigation


    【解决方案1】:

    试着把这个android:checkable="true"放在商品代码中

    【讨论】:

      【解决方案2】:
      What you can do is take 2 images of checkbox, one for checked and other for unchecked.
      The onclick you may toggle between images, it will give simulation of checkbox. 
      
      also you must be using drawer layout for navigation menu 
      xml
      <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:fab="http://schemas.android.com/apk/res-auto"
          android:id="@+id/root"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:theme="@style/AlertDialog.AppCompat.Light"
          android:fitsSystemWindows="true">
      
      
      Codebehind
      
      mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                  @Override
                  public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                      mDrawerLayout.closeDrawers();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-02-01
        • 1970-01-01
        • 1970-01-01
        • 2016-11-21
        • 2016-10-11
        • 2015-03-14
        • 2023-04-11
        • 1970-01-01
        相关资源
        最近更新 更多