1.創建Service繼承TileService
import android.content.Intent
import android.provider.Settings
import android.service.quicksettings.TileService
class MyTileService : TileService() {
override fun onClick() {
super.onClick()
//點擊後跳轉到設定日期(創建新頁面)
val intent = Intent(Settings.ACTION_DATE_SETTINGS).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK
}
//跳轉並關閉快速設置面板
startActivityAndCollapse(intent)
}
}
2.聲明Service
<service android:name=".MyTileService"
android:label="@string/app_name"
android:icon="@drawable/ic_date"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE"/>
</intent-filter>
</service>
3.效果展示
Github
連結網址