Day 6 of Android Development

 Hello everyone, Today i learned to make intractive freature in my app basically i can switch in dark mode to reading mode and from reading mode to dark mode, And then about Types of layouts. 


  • Linear layout
  • Relative layout
  • constraint layout

and last, Android app activity lifecycle.

TELEGRAM FOR APKS :-https://t.me/+hZu9-FaImzAyYmU1



There are so many code are running but i only kotlin and some XML codes

INTRACTIVE APP

KOTLIN CODE

package com.example.intractiveapp

import android.os.Bundle
import android.widget.Button
import android.widget.LinearLayout
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.intractiveapp.R

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_main)

val buttonDark = findViewById<Button>(R.id.btnDark)
val buttonRead = findViewById<Button>(R.id.btnRead)
val layout = findViewById<LinearLayout>(R.id.linearLayout)

buttonRead.setOnClickListener {
layout.setBackgroundResource(R.color.cream)
}

buttonDark.setOnClickListener {
layout.setBackgroundResource(R.color.black)
}

ViewCompat.setOnApplyWindowInsetsListener(layout) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
}
}



XML CODE
<?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/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:orientation="vertical"
tools:context=".MainActivity">

<Button
android:id="@+id/btnDark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:fontFamily="monospace"
android:padding="10dp"
android:text="Dark" />

<Button
android:id="@+id/btnRead"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:fontFamily="monospace"
android:padding="10dp"
android:text="Read" />
</LinearLayout>



XML COLOR CODE
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="cream">#FFFDD0</color>
</resources>





LAYOUT APP

KOTLIN CODE

package com.example.layouts

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_main)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
}
}


XML CODE 

<?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:orientation="vertical"
tools:context=".MainActivity">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />

<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>

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

<ImageButton
android:id="@+id/imageButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:srcCompat="@tools:sample/avatars" />

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />

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


THANK YOU
GOOD NIGHT

Comments