简体   繁体   English

首次在android应用中加载布局时如何添加提示

[英]How to add hints during the loading of layout in the android app for the first time

How to add hints during the loading of layout in the app for the first time. 首次在应用程序中加载布局时如何添加提示。 I am attaching the screenshot taken from a app. 我附上了从应用程序中截取的屏幕截图。 Any reply will be helpful. 任何回复都将有所帮助。

在此处输入图片说明

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: 接下来,在应该显示提示的ActivityFragment的布局中,在底部添加一个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: 最后,在ActivityonCreateFragment 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM