Reputation: 371
I want to use custom toggle buttons. Currently I use the following xml file to define a "custom" background:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/switchon" android:state_checked="true" />
<item android:drawable="@drawable/switchoff" android:state_checked="false"/>
</selector>
with
and
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FF0000" />
<corners android:bottomRightRadius="35dp"
android:bottomLeftRadius="35dp"
android:topRightRadius="35dp"
android:topLeftRadius="35dp"/>
</shape>
as background.
When I include the button in the layout with the following code, it produces a red/green toggle button.
<ToggleButton
android:id="@+id/ToggleButton1"
android:layout_height="50dp"
android:layout_marginRight="30dp"
android:background="@drawable/toggle_button"
android:text=""
android:textOff=""
android:textOn=""
android:layout_marginStart="99dp"
android:layout_marginTop="84dp"
android:layout_width="50dp"
android:layout_below="@+id/section_label"
android:layout_toEndOf="@+id/section_label"
style="@android:style/Widget.Button.Toggle"
android:checked="true" />
Now i want this button to have a certain elevation. Adding android:elevation="2dp" does not produce any effect.
Can anyone tell me how to do that? I was not able to find a solution to that.
Upvotes: 3
Views: 2379
Reputation: 371
To solve the issue I put a CardView beneath the Toggle button. Setting an elevation did work right away with the card view.
Thanks for the input! :-)
Upvotes: 1
Reputation: 729
Hey Use SwitchCompat instead of Toggle button
<android.support.v7.widget.SwitchCompat
android:id="@+id/Switch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textOff=""
android:text="Toggle Switch"
android:background="@android:color/transparent"
android:textOn=""
android:elevation="5dp"
android:button="@null"
android:padding="20dp"/>
This will definatly works
Upvotes: 0