Triet Nguyen
Triet Nguyen

Reputation: 821

android - Set switch button into action bar with showAsAction="never"

I want to put a switch button into MenuItem with showAsAction="never" but it's not working. Here is my layout

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.trietnhm.multipleactivities.MainActivity"
    >


    <item
        android:id="@+id/action_about"
        android:orderInCategory="0"
        app:showAsAction="never"
        android:title="About"/>
    <item
        android:id="@+id/action_change_theme"
        android:orderInCategory="3"
        app:actionLayout="@layout/switcher"
        app:showAsAction="never"
        android:title="" />
    <item
        android:id="@+id/action_change_delimeter"
        android:orderInCategory="2"
        app:showAsAction="never"
        android:title="Change Delimeter"/>
</menu>

This my Switch button

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

    <android.support.v7.widget.SwitchCompat
        android:id="@+id/switchForActionBar"
        android:layout_width="70dp"
        android:layout_height="50dp"
        android:scaleX="1.3"
        android:scaleY="1.3"
        android:switchMinWidth="45dp"
        android:paddingTop="6dp" />

</RelativeLayout>

When I run the app and it's not show anything. Here the image https://drive.google.com/file/d/0B5zsq6J-qyY5bF8tYnBKVy11OHM/view?usp=sharing

Any help I would be appreciated. Thanks all.

Upvotes: 1

Views: 533

Answers (3)

Nidhi Pandya
Nidhi Pandya

Reputation: 198

why are you using app:showAsAction="Never"?? for that you can also use app:showAsAction="ifRoom" or app:showAsAction="ifRoom|collapseActionView"

Upvotes: 0

ʍѳђઽ૯ท
ʍѳђઽ૯ท

Reputation: 16976

android:showAsAction

never :

Never place this item in the app bar. Instead, list the item in the app bar's overflow menu.

Of course, It won't show up. Perhaps you should use other options to show, always or ifRoom.

Upvotes: 1

SaTech
SaTech

Reputation: 430

This line code

android:orientation="vertical"  

is used with LinearLayout not with RelativeLayout

Upvotes: 0

Related Questions