2016-01-28 29 views
6

Tôi đang cố thêm công tắc (hộp kiểm làm tùy chọn thứ hai) vào ngăn điều hướng. "Trang trình bày trong menu". Giá trị mặc định bạn sẽ nhận được khi tạo dự án mới bằng ngăn điều hướng.Chuyển trong ngăn điều hướng Android

Tôi đã thử một dự án mới mẻ nên tôi không làm hỏng dự án 'thực sự' của mình.

I tried this from SO

Nhưng không may mắn. Dường như không thể tìm thấy bất cứ điều gì đáng nói đến ..

Tôi đang cố thêm công tắc ở menu cuối cùng. activity_main_drawer.xml:

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android"> 

<group android:checkableBehavior="single"> 
    <item 
     android:id="@+id/nav_camera" 
     android:icon="@drawable/ic_menu_camera" 
     android:title="Import" 
     android:checkable="true"/> 
    <item 
     android:id="@+id/nav_gallery" 
     android:icon="@drawable/ic_menu_gallery" 
     android:title="Gallery" /> 
    <item 
     android:id="@+id/nav_slideshow" 
     android:icon="@drawable/ic_menu_slideshow" 
     android:title="Slideshow" /> 
    <item 
     android:id="@+id/nav_manage" 
     android:icon="@drawable/ic_menu_manage" 
     android:title="Tools" /> 
</group> 

<item android:title="Communicate"> 
    <menu> 
     <item 
      android:id="@+id/nav_share" 
      android:icon="@drawable/ic_menu_share" 
      android:title="Share" /> 
     <item 
      android:id="@+id/nav_send" 
      android:icon="@drawable/ic_menu_send" 
      android:title="Send" /> 
     <item 
      android:id="@+id/myswitch" 
      android:title="" 
      android:actionLayout="@layout/ttt" 
      /> 
    </menu> 
</item> 
</menu> 

ttt.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal" > 

<Switch 
    android:id="@+id/ss" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="" /> 

</RelativeLayout> 

Mục cuối cùng "id/myswitch" doens't chương trình ở tất cả. MainActivity.java là mặc định 100%. Đó là lý do tại sao tôi không đăng nó.

Trả lời

3

Thay vì:

<item 
    android:id="@+id/myswitch" 
    android:title="" 
    android:actionLayout="@layout/ttt" 
    /> 

viết:

<item 
    android:id="@+id/myswitch" 
    android:title="" 
    app:actionLayout="@layout/ttt" 
    /> 

Thay đổi android:actionLayout để app:actionLayout.

+3

Làm cách nào để thêm người nghe vào công tắc trong ngăn điều hướng. – mogren3000

+0

Làm cách nào để thêm người nghe vào công tắc trong ngăn điều hướng? – rochasdv

+0

rochasdv & mogren3000: Tôi đã sử dụng một cách tiếp cận khác. Trong thực tế, tôi phát hiện ra rằng bạn có thể sử dụng * bất kỳ * xem trong ngăn kéo, do đó, không có điểm trong làm phiền với các công cụ trình đơn. Chỉ cần tạo chế độ xem theo cách thông thường (với người nghe, v.v.) và thêm vào ngăn kéo. – lenooh

Các vấn đề liên quan