当前位置:网站首页>Timed disappearance pop-up

Timed disappearance pop-up

2022-07-05 10:16:00 asahi_ xin

preparation
1. Call parameters

    <!-- Color -->
   <color name="transparent">#00000000</color>
   <color name="black">#000000</color>
   <color name="white">#FFFFFF</color>
   <!-- font size -->
   <dimen name="text_size_16sp">16sp</dimen>
   <!-- written words -->
   <string name="close_after__seconds">%s Seconds to close </string>
   <!-- style -->
   <style name="sp_dialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowFrame">@null</item> <!--  Frame  -->
        <item name="android:windowIsFloating">true</item> <!--  Whether it appears in activity above  -->
        <item name="android:windowIsTranslucent">false</item> <!--  translucent  -->
        <item name="android:windowNoTitle">true</item> <!--  No title  -->
        <item name="android:windowBackground">@android:color/transparent</item> <!--  The background is transparent  -->
        <item name="android:backgroundDimEnabled">true</item> <!--  Fuzzy  -->
   </style>

2. background
dialog_common_bg

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="20dp" />
    <solid android:color="@color/white" />
    <stroke
        android:width="1dp"
        android:color="@color/white" />
</shape>

3. picture
 Insert picture description here
Main code

public class WaitTimeDialog extends Dialog {
    

    public WaitTimeDialog(@NonNull Context context, int themeResId) {
    
        super(context, themeResId);
    }

    public static void create(Context context, int millisInFuture, int countDownInterval) {
    
        WaitTimeDialog dialog = new WaitTimeDialog(context, R.style.sp_dialog);
        dialog.setContentView(R.layout.dialog_wait_time);
        dialog.setCancelable(false);
        dialog.show();

        TextView tip = dialog.findViewById(R.id.tip);
        tip.setText(String.format(context.getString(R.string.close_after__seconds), millisInFuture + ""));
        CountDownTimer countDownTimer = new CountDownTimer((millisInFuture + countDownInterval) * 1000, countDownInterval * 1000) {
    

            @Override
            public void onTick(long millisUntilFinished) {
    
                tip.setText(String.format(context.getString(R.string.close_after__seconds), millisUntilFinished / 1000 + ""));
            }

            @Override
            public void onFinish() {
    
                dialog.dismiss();
            }
        };
        countDownTimer.start();
    }
}

dialog_wait_time

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="130dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:background="@color/transparent"
    android:orientation="vertical">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/dialog_common_bg"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/img"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_centerHorizontal="true"
            android:layout_gravity="center"
            android:layout_marginTop="20dp"
            android:src="@drawable/icon_confirm" />

        <TextView
            android:id="@+id/tip"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/img"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="10dp"
            android:gravity="center"
            android:textColor="@color/black"
            android:textSize="@dimen/text_size_16sp" />
    </RelativeLayout>
</LinearLayout>
原网站

版权声明
本文为[asahi_ xin]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140534181674.html