[英]How to add hints during the loading of layout in the android app for the first time
First, create the layout for the hint overlay: 首先,创建提示覆盖的布局:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your text here"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Got it!"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Next, in the layout of the Activity
or Fragment
that the hint should be shown over, add a ViewStub
at the bottom: 接下来,在应该显示提示的
Activity
或Fragment
的布局中,在底部添加一个ViewStub
:
<ViewStub android:id="@+id/stub"
android:inflatedId="@+id/subTree"
android:layout="@layout/hintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Finally, in the onCreate
of your Activity
or onCreateView
of your Fragment
, inflate the stub if it hasn't already been shown by checking SharedPreferences: 最后,在
Activity
的onCreate
或Fragment
onCreateView
中,如果尚未显示存根,则通过检查SharedPreferences对其进行充气:
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(applicationContext)
val hasShownHint = sharedPreferences.getBoolean("showedHint", false)
if (!hasShownHint) {
val stub = findViewById(R.id.stub);
stub.inflate();
val editor = sharedPreferences.edit()
editor.putBoolean("showedHint", true)
}
您可以检查此库,这可能对您有所帮助,这是链接https://github.com/TakuSemba/Spotlight
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.