当前位置:网站首页>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>
边栏推荐
- @JsonAdapter注解使用
- 把欧拉的创新带向世界 SUSE 要做那个引路人
- Wechat applet - simple diet recommendation (3)
- Tianlong Babu TLBB series - about items dropped from packages
- Usage differences between isempty and isblank
- LiveData 面试题库、解答---LiveData 面试 7 连问~
- Node red series (29): use slider and chart nodes to realize double broken line time series diagram
- 一种用于干式脑电图的高密度256通道电极帽
- QT event filter simple case
- 面试:List 如何根据对象的属性去重?
猜你喜欢
(1) Complete the new construction of station in Niagara vykon N4 supervisor 4.8 software
ArcGIS Pro 创建要素
The king of pirated Dall · e? 50000 images per day, crowded hugging face server, and openai ordered to change its name
Events and bubbles in the applet of "wechat applet - Basics"
Redis如何实现多可用区?
QT timer realizes dynamic display of pictures
宝塔面板MySQL无法启动
一个程序员的职业生涯到底该怎么规划?
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
Design and Simulation of fuzzy PID control system for liquid level of double tank (matlab/simulink)
随机推荐
MySQL character type learning notes
Getting started with Apache dolphin scheduler (one article is enough)
Swift uses userdefaults and codable to save an array of class objects or structure instances
QT timer realizes dynamic display of pictures
Z-blog template installation and use tutorial
uniapp + uniCloud+unipay 实现微信小程序支付功能
Theme. AppCompat. Light. Darkactionbar not found
[system design] index monitoring and alarm system
微信小程序中,从一个页面跳转到另一个页面后,在返回后发现页面同步滚动了
oracle和mysql批量Merge对比
LiveData 面试题库、解答---LiveData 面试 7 连问~
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
QT event filter simple case
Mysql80 service does not start
请问大佬们 有遇到过flink cdc mongdb 执行flinksql 遇到这样的问题的么?
Zblogphp breadcrumb navigation code
.Net之延迟队列
Tianlong Babu TLBB series - about items dropped from packages
C function returns multiple value methods
【系统设计】指标监控和告警系统