当前位置:网站首页>Universal double button or single button pop-up
Universal double button or single button pop-up
2022-07-05 10:16:00 【asahi_ xin】
preparation
1. Color value
<color name="white">#FFFFFF</color>
<color name="black">#000000</color>
<color name="gray">#c8c7cc</color>
<color name="deep_blue">#616EFD</color>
<!-- transparent -->
<color name="transparent">#00000000</color>
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>
dialog_common_botton_button_bg
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="@color/white" />
<corners
android:bottomRightRadius="20dp"
android:bottomLeftRadius="20dp"
/>
<padding
android:bottom="8dp"
android:left="18dp"
android:right="18dp"
android:top="8dp" />
</shape>
dialog_common_left_button_bg
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:bottomLeftRadius="20dp" />
<padding
android:bottom="8dp"
android:left="18dp"
android:right="18dp"
android:top="8dp" />
<solid android:color="@color/white" />
</shape>
dialog_common_right_button_bg
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/deep_blue" />
<corners android:bottomRightRadius="20dp" />
<padding
android:bottom="8dp"
android:left="18dp"
android:right="18dp"
android:top="8dp" />
</shape>
dialog_common_title_bg
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:topLeftRadius="50dp"
android:topRightRadius="50dp" />
<solid android:color="@color/white" />
<size
android:width="75dp"
android:height="75dp"
/>
</shape>
3. picture 
4. style
<!-- Dialog box -->
<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>
5. Text and size
<dimen name="text_size_16sp">16sp</dimen>
<string name="cancel"> Cancel </string>
<string name="confirm"> determine </string>
<string name="tip"> Tips </string>
Main code
CommonDialog
public class CommonDialog extends Dialog {
public CommonDialog(@NonNull Context context, int themeResId) {
super(context, themeResId);
}
public static CommonDialog createOneButton(Context context, String msg,
String btnText1, DialogInterface.OnClickListener mOnClickListener1) {
CommonDialog.Builder dialogBuilder = new CommonDialog.Builder(context);
dialogBuilder.setMessage(msg);
dialogBuilder.addButton(btnText1, mOnClickListener1);
CommonDialog dialog = dialogBuilder.create();
dialog.setCanceledOnTouchOutside(false);
dialog.show();
return dialog;
}
public static CommonDialog createTwoButton(Context context, String msg,
String btnText1, DialogInterface.OnClickListener mOnClickListener1,
String btnText2, DialogInterface.OnClickListener mOnClickListener2) {
CommonDialog.Builder dialogBuilder = new CommonDialog.Builder(context);
dialogBuilder.setMessage(msg);
dialogBuilder.addButton(btnText1, mOnClickListener1);
dialogBuilder.addButton(btnText2, mOnClickListener2);
CommonDialog dialog = dialogBuilder.create();
dialog.setCanceledOnTouchOutside(false);
dialog.show();
return dialog;
}
public static class Builder {
private Context context;
private CharSequence message;
private List<String> btnTextList;
private List<DialogInterface.OnClickListener> btnListenerList;
Builder(Context context) {
this.context = context;
btnTextList = new ArrayList<>();
btnListenerList = new ArrayList<>();
}
public Builder setMessage(CharSequence message) {
this.message = message;
return this;
}
public Builder setMessage(int message) {
this.message = context.getText(message);
return this;
}
void addButton(String text, OnClickListener listener) {
btnTextList.add(text);
btnListenerList.add(listener);
}
public CommonDialog create() {
final CommonDialog dialog = new CommonDialog(context, R.style.sp_dialog);
dialog.setCancelable(false);
dialog.setContentView(R.layout.dialog_common);
if (message != null) {
TextView textMessage = dialog.findViewById(R.id.tip);
textMessage.setText(message);
textMessage.setMovementMethod(ScrollingMovementMethod.getInstance());
}
Button btn1 = dialog.findViewById(R.id.left);
Button btn2 = dialog.findViewById(R.id.right);
int btnSize = btnListenerList.size();
int btnSizeOne = 1;
int btnSizeTwo = 2;
if (btnSize == btnSizeOne) {
btn1.setText(btnTextList.get(0));
btn1.setOnClickListener(v -> btnListenerList.get(0).onClick(dialog, 0));
btn1.setVisibility(View.VISIBLE);
btn1.setBackgroundResource(R.drawable.dialog_common_botton_button_bg);
btn2.setVisibility(View.GONE);
} else if (btnSize >= btnSizeTwo) {
btn1.setText(btnTextList.get(0));
btn1.setOnClickListener(v -> btnListenerList.get(0).onClick(dialog, 0));
btn2.setText(btnTextList.get(1));
btn2.setOnClickListener(v -> btnListenerList.get(1).onClick(dialog, 1));
btn1.setVisibility(View.VISIBLE);
btn2.setVisibility(View.VISIBLE);
}
return dialog;
}
}
}
dialog_common
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="260dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="@color/transparent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:background="@drawable/dialog_common_bg"
android:orientation="vertical">
<TextView
android:id="@+id/tip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginTop="100dp"
android:gravity="center"
android:textColor="@color/black"
android:textSize="@dimen/text_size_16sp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/gray" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/left"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/dialog_common_left_button_bg"
android:gravity="center"
android:text="@string/cancel"
android:textColor="@color/deep_blue"
android:textSize="@dimen/text_size_16sp"
tools:ignore="ButtonStyle" />
<Button
android:id="@+id/right"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/dialog_common_right_button_bg"
android:gravity="center"
android:text="@string/confirm"
android:textColor="@color/white"
android:textSize="@dimen/text_size_16sp"
tools:ignore="ButtonStyle" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="@drawable/dialog_common_title_bg"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="32.5dp"
android:layout_height="32.5dp"
android:layout_marginTop="10dp"
android:src="@drawable/icon_dialog_tip"
tools:ignore="ContentDescription" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/tip"
android:textColor="@color/deep_blue"
android:textSize="@dimen/text_size_18sp" />
</LinearLayout>
</RelativeLayout>
边栏推荐
- Unity particle special effects series - the poison spray preform is ready, and the unitypackage package is directly used - on
- Livedata interview question bank and answers -- 7 consecutive questions in livedata interview~
- Is it really reliable for AI to make complex decisions for enterprises? Participate in the live broadcast, Dr. Stanford to share his choice | qubit · viewpoint
- The essence of persuasion is to remove obstacles
- 把欧拉的创新带向世界 SUSE 要做那个引路人
- uniapp + uniCloud+unipay 实现微信小程序支付功能
- Comparison of batch merge between Oracle and MySQL
- 如何获取GC(垃圾回收器)的STW(暂停)时间?
- 钉钉、企微、飞书学会赚钱了吗?
- The horizontally scrolling recycleview displays five and a half on one screen, lower than the average distribution of five
猜你喜欢

> Could not create task ‘:app:MyTest. main()‘. > SourceSet with name ‘main‘ not found. Problem repair

Kotlin Compose 多个条目滚动

Wechat applet - simple diet recommendation (2)

.Net之延迟队列

ConstraintLayout的流式布局Flow

到底谁才是“良心”国产品牌?

双容水箱液位模糊PID控制系统设计与仿真(Matlab/Simulink)

Wechat applet - simple diet recommendation (4)

How to plan the career of a programmer?
![[NTIRE 2022]Residual Local Feature Network for Efficient Super-Resolution](/img/f3/782246100bca3517d95869be80d9c5.png)
[NTIRE 2022]Residual Local Feature Network for Efficient Super-Resolution
随机推荐
RMS TO EAP通过MQTT简单实现
@Jsonadapter annotation usage
AtCoder Beginner Contest 258「ABCDEFG」
Theme. AppCompat. Light. Darkactionbar not found
The king of pirated Dall · e? 50000 images per day, crowded hugging face server, and openai ordered to change its name
ByteDance Interviewer: how to calculate the memory size occupied by a picture
把欧拉的创新带向世界 SUSE 要做那个引路人
MySQL字符类型学习笔记
QT event filter simple case
微信小程序中,从一个页面跳转到另一个页面后,在返回后发现页面同步滚动了
如何写出高质量的代码?
How to get the STW (pause) time of GC (garbage collector)?
.Net之延迟队列
ConstraintLayout官方提供圆角ImageFilterView
MySQL数字类型学习笔记
Those who are good at using soldiers, hide in the invisible, and explain the best promotional value works in depth in 90 minutes
Have you learned to make money in Dingding, enterprise micro and Feishu?
请问大佬们 有遇到过flink cdc mongdb 执行flinksql 遇到这样的问题的么?
pytorch输出tensor张量时有省略号的解决方案(将tensor完整输出)
Dedecms website building tutorial