Primeiro, crie o layout para a sobreposição de dica:
<?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>
Em seguida, no layout do Activity
ou em Fragment
que a dica deve ser mostrada, adicione um ViewStub
na parte inferior:
<ViewStub android:id="@+id/stub"
android:inflatedId="@+id/subTree"
android:layout="@layout/hintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Finalmente, no onCreate
de seu Activity
ou onCreateView
de seu Fragment
, aumente o stub se ele ainda não tiver sido mostrado marcando 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)
}
Este artigo é coletado da Internet.
Se houver alguma infração, entre em [email protected] Delete.
deixe-me dizer algumas palavras