No result illustrationNo result illustration

DevLoom

search

Lets Connect

chevron right
Menu
Home

Home

Community

Community

Blog Posts

Blog Posts

Programming

Programming

Tech Topics

Tech Topics

Explore

Explore

Find Jobs

Find Jobs

Tags

Tags

DevLoomPerfect Place for devs
    profile

    SHAIK JUBER AHMED

    upvoteupvote

    0

    downvote

    0

    starstar

    Basic Interactivity UI in Kotlin

    clock icon

    Asked 11 months ago

    message

    0 Answers

    eye

    1 Views

    in Linear Layout ! Create 2 Buttons in in activity_main.xml

     

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 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/main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="20dp"
        android:orientation="vertical"
        tools:context=".MainActivity">
    
    
        <Button
            android:id="@+id/dark"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20.dp"
            android:text="Dark theme" />
    
        <Button
            android:id="@+id/light"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Light Theme" />
    </LinearLayout>

    and In MainActivity ! Define the button Variablers and we can change the color on click ! (setBackgroundResource) is the in Build function helps in changing the background

      // Changing Themes using Buttons !
    
            val buttonDark = findViewById<Button>(R.id.dark)
            val buttonLight = findViewById<Button>(R.id.light)
            val layout = findViewById<LinearLayout>(R.id.main)
    
            buttonDark.setOnClickListener {
                layout.setBackgroundResource(R.color.black)
            }
    
            buttonLight.setOnClickListener {
                layout.setBackgroundResource(R.color.white)
            }
    

    Share

    Android
    Kotlin

    Write your answer here

    Answer Similar Questions!

    12 months ago

    Step-by-Step Guide for Kotlin Android Development

    Kotlin
    roadmap
    Android
    user

    SHAIK JUBER AHMED - asked 12 months ago

    Upvotes

    0 Votes

    message

    0 Answers

    eye

    13 Views

    11 months ago

    Loyouts in Kotlin !

    Android
    Kotlin
    AppDev
    user

    SHAIK JUBER AHMED - asked 11 months ago

    Upvotes

    0 Votes

    message

    0 Answers

    eye

    0 Views

    0 Responses