看效果图
1.入口
<application
android:allowBackup="true"
android:icon="@mipmap/timg"
android:label="@string/app_name"
android:roundIcon="@mipmap/timg"
android:supportsRtl="true"
android:excludeFromRecents="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar">//设置透明背景
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
2.布局
<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="match_parent"
android:background="@null"
tools:context=".MainActivity">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
3.界面
class MainActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
OnVolumeAddKey()
}
fun OnVolumeAddKey() {
try {
val keyCommand = "input keyevent " + KeyEvent.KEYCODE_VOLUME_UP
val runtime = Runtime.getRuntime()
val proc = runtime.exec(keyCommand)
} catch (e: IOException) {
e.printStackTrace()
}
text.postDelayed(Runnable {
finish()
}, 1000)
}
override fun onDestroy() {
super.onDestroy()
finish()
}
}
|