We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All

Documents from this version have been archived, and will not continue to be maintained. Please use the latest version.

HMS Core GuidesScan KitAppendixCustom Elements for the Scanning UI in Customized View Mode

Custom Elements for the Scanning UI in Customized View Mode

Commonly used elements are listed as follows for your reference:

  • Custom title

Use title to define text information. The following is a configuration example in the layout file:

Collapse
Word wrap
Dark theme
Copy code
  1. <TextView  
  2.    android:layout_marginStart="10sp"  
  3.    android:layout_toEndOf="@+id/back_img"  
  4.    android:layout_width="match_parent"  
  5.    android:layout_height="match_parent"  
  6.    android:gravity="center_vertical"  
  7.    android:text="@string/title"  
  8.    android:textAllCaps="false"  
  9.    android:textColor="#FFFFFF"  
  10.    android:textSize="20sp"  
  11.    android:textStyle="bold" />
  • Custom back button

Define the element of the back button whose ID is back_img and bind the element to the go-back operation. The following is a configuration example in the layout file:

Collapse
Word wrap
Dark theme
Copy code
  1. <ImageView  
  2.    android:id="@+id/back_img"  
  3.    android:layout_width="48dp"  
  4.    android:layout_height="48dp"  
  5.    android:padding="12dp"  
  6.    android:layout_alignParentStart="true"  
  7.    android:layout_marginStart="12dp"  
  8.    android:layout_marginTop="4dp"  
  9.    android:gravity="center"  
  10.    android:src="@drawable/back" />

The following is an example of binding the go-back operation in the customized activity:

Collapse
Word wrap
Dark theme
Copy code
  1. private void setBackOperation() {  
  2.    backBtn = findViewById(R.id.back_img);  
  3.    backBtn.setOnClickListener(new View.OnClickListener() {  
  4.        @Override  
  5.        public void onClick(View v) {  
  6.            DefinedActivity.this.finish();  
  7.        }  
  8.    });  
  9. }
  • Custom flashlight button

Define the element of the flashlight button and bind the element to the operations of turning on and off the flashlight. The following is a configuration example in the layout file:

Collapse
Word wrap
Dark theme
Copy code
  1. <ImageView  
  2.    android:id="@+id/flush_btn"  
  3.    android:layout_width="48dp"  
  4.    android:layout_height="48dp"  
  5.    android:layout_alignParentBottom="true"  
  6.    android:layout_centerHorizontal="true"  
  7.    android:visibility="gone"  
  8.    android:gravity="center"  
  9.    android:src="@drawable/flashlight_off" />

The following is an example of binding the flashlight button in the customized activity:

Collapse
Word wrap
Dark theme
Copy code
  1. private void setFlashOperation() {  
  2.    flushBtn.setOnClickListener(new View.OnClickListener() {  
  3.        @Override  
  4.        public void onClick(View v) {  
  5.            if (remoteView.getLightStatus()) {  
  6.                remoteView.switchLight();  
  7.                flushBtn.setImageResource(img[1]);  
  8.            } else {  
  9.                remoteView.switchLight();  
  10.                flushBtn.setImageResource(img[0]);  
  11.            }  
  12.        }  
  13.    });  
  14. }
  • Custom scanning UI

Draw a scanning box. The following is a configuration example in the layout file:

Collapse
Word wrap
Dark theme
Copy code
  1. <RelativeLayout  
  2.    android:layout_width="match_parent"  
  3.    android:layout_height="match_parent">  
  4.    <ImageView  
  5.        android:layout_width="match_parent"  
  6.        android:layout_height="match_parent"  
  7.        android:layout_centerInParent="true"  
  8.        android:layout_centerHorizontal="true"  
  9.        android:background="#FF000000"  
  10.        android:alpha="0.1" />  
  11.    <TextView  
  12.        android:layout_marginTop="225dp"  
  13.        android:layout_centerHorizontal="true"  
  14.        android:text="@string/scan_tip"  
  15.        android:textAllCaps="false"  
  16.        android:textColor="#FFFFFF"  
  17.        android:textSize="15sp"  
  18.        android:textStyle="bold"  
  19.        android:layout_height="20dp"  
  20.        android:layout_width="220dp" />  
  21.    <!-- Set the scanning box.-->
  22.    <ImageView  
  23.        android:layout_width="300dp"  
  24.        android:layout_height="300dp"  
  25.        android:layout_centerInParent="true"  
  26.        android:layout_centerHorizontal="true"  
  27.        android:background="@drawable/cloors" />  
  28. </RelativeLayout>

Define the scanning box border style.

Collapse
Word wrap
Dark theme
Copy code
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android"  
  3.    android:shape="rectangle">  
  4.    <!-- Set the border width and color. -->
  5.    <stroke android:width="3dp" android:color="#e1ffff"/>  
  6.    <!-- Set the fill color within the scanning box. -->
  7.    <solid android:color="#1f00BCD4"/>  
  8.    <!-- Set the round corner. -->
  9.    <corners android:radius="5dip"/>  
  10.    <!-- Set the padding. -->
  11.    <padding  
  12.        android:left="2dp"  
  13.        android:top="2dp"  
  14.        android:right="2dp"  
  15.        android:bottom="2dp" />  
  16. </shape>


This page may contain third-party content. For details, click here.