Skip to content

Instantly share code, notes, and snippets.

@DjangoLC
Created July 12, 2020 23:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DjangoLC/5dc0051c701831aeddf192b55cce69ef to your computer and use it in GitHub Desktop.
Save DjangoLC/5dc0051c701831aeddf192b55cce69ef to your computer and use it in GitHub Desktop.
custom switch layout
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
android:id="@+id/custom_switch_container"
android:layout_width="222dp"
android:layout_height="33dp"
android:background="@drawable/shape"
android:backgroundTint="#82BC00"
android:clickable="true"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/imgShape"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_gravity="center|start"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:layout_marginEnd="4dp"
android:background="@drawable/shape"
android:clickable="false"
app:layout_constraintBottom_toBottomOf="parent"
tools:layout_editor_absoluteX="95dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="10dp">
<TextView
android:id="@+id/tvOn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:padding="4dp"
android:text="@string/off"
android:textColor="#80000000"
android:textStyle="bold" />
<TextView
android:id="@+id/tvOff"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="12dp"
android:layout_marginLeft="12dp"
android:layout_weight="1"
android:gravity="center"
android:paddingStart="8dp"
android:paddingLeft="8dp"
android:paddingTop="4dp"
android:paddingEnd="8dp"
android:paddingBottom="4dp"
android:text="@string/on"
android:textColor="@android:color/white"
android:textStyle="bold" />
</LinearLayout>
</FrameLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment