首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安卓材料设计导航视图->项目

安卓材料设计导航视图->项目
EN

Stack Overflow用户
提问于 2015-07-23 07:59:48
回答 1查看 876关注 0票数 7

有人能告诉我如何添加一个切换按钮到android材料设计导航视图吗?

项目从菜单项中添加。

drawer_menu_items.xml

代码语言:javascript
复制
<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" />

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

EN

回答 1

Stack Overflow用户

发布于 2015-10-04 12:41:41

代码语言:javascript
复制
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();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31581407

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档