"Coach mark" คือ "Help overlay" ใน UX talk :-)
coach_mark.xmlคือรูปแบบเครื่องหมายโค้ชของคุณ
coach_mark_master_viewคือ id ของมุมมองสูงสุดอันดับต้น ๆ (root) ในcoach_mark.xml
public void onCoachMark(){
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setContentView(R.layout.coach_mark);
dialog.setCanceledOnTouchOutside(true);
View masterView = dialog.findViewById(R.id.coach_mark_master_view);
masterView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
dialog.show();
}
การเพิ่มตัวอย่างของ coach_mark.xml (ลงในโซลูชันที่ยอดเยี่ยมนี้มอบให้โดย Oded Breiner) ดังนั้นจึงเป็นเรื่องง่ายสำหรับ ppl ในการคัดลอกและวางเพื่อดูตัวอย่างการทำงานอย่างรวดเร็ว
ตัวอย่าง coach_mark.xml ที่นี่เปลี่ยน -> drawable / coach_marks เป็นรูปภาพของคุณ:
coach_mark.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/coach_mark_master_view">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/coach_marks_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal"
android:src="@drawable/coach_marks" />
</RelativeLayout>
</LinearLayout>
และสามารถเลือกใช้ชุดรูปแบบนี้เพื่อลบช่องว่างภายใน:
<style name="WalkthroughTheme" parent="Theme.AppCompat">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>