Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switchcompat not displaying the Switch

I am trying to use the latest appcompat which was updated for material design in my app to show the switch view as displayed in Lollipop(http://android-developers.blogspot.in/2014/10/appcompat-v21-material-design-for-pre.html), the problem is the switch is not getting displayed. My SDKmin is 14 and max is 21. I am using the below code in the layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/fragment_scheduler"
    tools:context="com.stackoverflow.ranjith.androidprojdel.SchedulerUI">

<android.support.v7.widget.SwitchCompat
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="switch"
        app:showText="false" />

    <Button
        android:layout_width="match_parent"
        android:text="start"
        android:id="@+id/start"
        android:layout_height="wrap_content" />
</LinearLayout>

Build.gradle:

dependencies {
    compile 'com.android.support:cardview-v7:+'
    compile 'com.android.support:recyclerview-v7:+'
    compile 'com.android.support:palette-v7:+'
    compile 'com.android.support:support-v4:+'
    compile "com.android.support:appcompat-v7:21.0.+"
    compile fileTree(dir: 'libs', include: ['*.jar'])
}
like image 446
Psypher Avatar asked Oct 25 '14 15:10

Psypher


1 Answers

I had same problem today but somehow it switchcompat worked in my sample. I think that there is problem with app style, it parent should be set to:

Theme.AppCompat
like image 129
3mpty Avatar answered Oct 09 '22 06:10

3mpty