android studio Ui design examples

 1 - make two view select and unselect in android studio

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    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:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="10dp"
    android:layout_marginTop="10dp"
    android:layout_marginEnd="10dp"
    android:background="@drawable/bg_switch"
    tools:context=".TryToggle">
    <TextView
        android:id="@+id/tvSwitchCust"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="20dp"
        android:layout_marginTop="15dp"
        android:layout_marginBottom="15dp"
        android:text="Customer"
        android:textColor="@color/white"
        android:textSize="24sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    <TextView
        android:id="@+id/tvSwitchpartn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="6dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="6dp"
        android:background="@drawable/bg_switch2"
        android:gravity="center"
        android:paddingStart="55dp"
        android:paddingTop="15dp"
        android:paddingEnd="45dp"
        android:paddingBottom="20dp"
        android:text="Partner"
        android:textColor="@color/black"
        android:textSize="24dp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

2 - write logic for selected  and unselected view :

private fun onClickListener() {
        binding.tvSwitchCust.setOnClickListener {
            binding.tvSwitchCust.setBackgroundResource(R.drawable.bg_switch2)
            binding.tvSwitchCust.setPadding(51,15,41,20)
            binding.tvSwitchCust.setTextColor(resources.getColor(R.color.black))
            binding.tvSwitchpartn.setTextColor(resources.getColor(R.color.white))
            binding.tvSwitchpartn.background = null
        }
        binding.tvSwitchpartn.setOnClickListener {
            binding.tvSwitchCust.background = null
            binding.tvSwitchpartn.setBackgroundResource(R.drawable.bg_switch2)
            binding.tvSwitchpartn.setPadding(65,15,55,20)
            binding.tvSwitchCust.setTextColor(resources.getColor(R.color.white))
            binding.tvSwitchpartn.setTextColor(resources.getColor(R.color.black))
        }
        binding.tvSignInProceed.setOnClickListener {
            val intent = Intent(this@Signup2Activity,CraetOtpActivity::class.java)
            startActivity(intent)
        }
    } p

Rajeshbhatt12

My name is Rajesh Bhatt. I am working as a senior android developer . I have created this blog for kotlin ,java and Android Development interview questions etc..

Previous Post Next Post