Android Q - Settings Panel
Published April 08, 2020Android Q Settings Panel
A Settings Panel is like a Bottom Sheet Floating Menu which allows us to view/edit the settings.
In the Android Q Settings Panel contains below Actions.
- ACTION_INTERNET_CONNECTIVITY
- ACTION_NFC
- ACTION_VOLUME
How we will call these actions in the application.
Let's check the example.
Step 1: Create Android Application
Step 2: Update activity_main.xml file with below code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
xmlns:app="https://schemas.android.com/apk/res-auto"
xmlns:tools="https://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:gravity="center"
android:background="@android:drawable/alert_light_frame"
android:orientation="vertical">
<Button
android:layout_width="220dp"
android:layout_height="40dp"
android:id="@+id/nfc_btn"
android:text="@string/nfc_panel"
android:background="@color/colorPrimary"
android:padding="8dp"
android:textSize="18sp"
android:layout_margin="8dp"
android:textColor="@color/colorWhite"/>
<Button
android:layout_width="220dp"
android:layout_height="40dp"
android:id="@+id/internet_btn"
android:text="@string/internet_panel"
android:background="@color/colorPrimary"
android:padding="8dp"
android:layout_margin="8dp"
android:textSize="18sp"
android:textColor="@color/colorWhite"/>
<Button
android:layout_width="220dp"
android:layout_height="40dp"
android:id="@+id/volume_btn"
android:text="@string/volume_panel"
android:background="@color/colorPrimary"
android:padding="8dp"
android:textSize="18sp"
android:layout_margin="8dp"
android:textColor="@color/colorWhite"/>
</LinearLayout>
|
Step 3: Update MainActivity.kt with below code
package com.rrtutors.androidq
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.content.Intent
import android.os.Build
import android.provider.Settings
import android.view.View
import android.widget.Toast
import androidx.annotation.RequiresApi
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//For Call NEF Settings panel
nfc_btn.setOnClickListener(View.OnClickListener {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
startActivity(Intent(Settings.Panel.ACTION_NFC))
} else {
Toast.makeText(applicationContext,"No Intent Found",Toast.LENGTH_LONG).show()
}
})
//FOr Internet Settings Panel
internet_btn.setOnClickListener(View.OnClickListener {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
startActivity(Intent(Settings.Panel.ACTION_INTERNET_CONNECTIVITY))
} else {
Toast.makeText(applicationContext,"No Intent Found",Toast.LENGTH_LONG).show()
}
//or ACTION_WIFI depending on what you want.
})
//For Volume Settings Panel
volume_btn.setOnClickListener(View.OnClickListener {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
startActivity(Intent(Settings.Panel.ACTION_VOLUME))
} else {
Toast.makeText(applicationContext,"No Intent Found",Toast.LENGTH_LONG).show()
}
})
}
}
|
Step 4: Run application
Article Contributed By :
|
|
|
|
1000 Views |