Compare commits
No commits in common. "5bf2bc9687449e9fa37330b8c142cf03e92d2529" and "9be3666af141d3b57811375ee0cd68ef9e05bf70" have entirely different histories.
5bf2bc9687
...
9be3666af1
|
|
@ -38,202 +38,6 @@ import androidx.core.content.ContextCompat;
|
|||
*/
|
||||
public class SlideDownView extends LinearLayout {
|
||||
|
||||
// ==================== Builder 模式支持 ====================
|
||||
/**
|
||||
* Builder类用于以链式调用方式构建SlideDownView实例
|
||||
*/
|
||||
public static class Builder {
|
||||
private final Context context;
|
||||
|
||||
// 可选参数(都有默认值)
|
||||
private String title = "";
|
||||
private float titleSize = 15f;
|
||||
private String content = "";
|
||||
private float contentSize = 12f;
|
||||
private int imageRes = 0;
|
||||
private int type = 0;
|
||||
private String backgroundColor = null;
|
||||
private int hideDuration = 300;
|
||||
private boolean viewCenter = true;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
* @param context 上下文
|
||||
*/
|
||||
public Builder(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置标题文本
|
||||
* @param title 标题
|
||||
* @return Builder实例
|
||||
*/
|
||||
public Builder setTitle(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置标题字号
|
||||
* @param titleSize 字号(sp)
|
||||
* @return Builder实例
|
||||
*/
|
||||
public Builder setTitleSize(float titleSize) {
|
||||
this.titleSize = titleSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置内容文本
|
||||
* @param content 内容
|
||||
* @return Builder实例
|
||||
*/
|
||||
public Builder setContent(String content) {
|
||||
this.content = content;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置内容字号
|
||||
* @param contentSize 字号(sp)
|
||||
* @return Builder实例
|
||||
*/
|
||||
public Builder setContentSize(float contentSize) {
|
||||
this.contentSize = contentSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置图标资源
|
||||
* @param imageRes 资源ID
|
||||
* @return Builder实例
|
||||
*/
|
||||
public Builder setImage(int imageRes) {
|
||||
this.imageRes = imageRes;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置类型(0=成功绿色,1=错误红色)
|
||||
* @param type 类型
|
||||
* @return Builder实例
|
||||
*/
|
||||
public Builder setType(int type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置背景颜色(字符串格式,如#FF0000)
|
||||
* @param color 颜色字符串
|
||||
* @return Builder实例
|
||||
*/
|
||||
public Builder setBackgroundColor(String color) {
|
||||
this.backgroundColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置背景颜色(ColorInt)
|
||||
* @param color 颜色值
|
||||
* @return Builder实例
|
||||
*/
|
||||
public Builder setBackgroundColor(int color) {
|
||||
this.backgroundColor = "#" + Integer.toHexString(color).substring(2);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置隐藏动画时长
|
||||
* @param duration 时长(毫秒)
|
||||
* @return Builder实例
|
||||
*/
|
||||
public Builder setHideDuration(int duration) {
|
||||
this.hideDuration = duration;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置内容是否居中
|
||||
* @param center 是否居中
|
||||
* @return Builder实例
|
||||
*/
|
||||
public Builder setViewCenter(boolean center) {
|
||||
this.viewCenter = center;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置成功样式(绿色背景)
|
||||
* @return Builder实例
|
||||
*/
|
||||
public Builder setSuccessStyle() {
|
||||
this.type = 0;
|
||||
this.backgroundColor = "#4CB050";
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置错误样式(红色背景)
|
||||
* @return Builder实例
|
||||
*/
|
||||
public Builder setErrorStyle() {
|
||||
this.type = 1;
|
||||
this.backgroundColor = "#FF4443";
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建SlideDownView实例
|
||||
* @return SlideDownView实例
|
||||
*/
|
||||
public SlideDownView build() {
|
||||
SlideDownView view = new SlideDownView(context);
|
||||
view.setTextTitle(this.title);
|
||||
view.setTextTitleSize((int) this.titleSize);
|
||||
view.setTextContent(this.content);
|
||||
view.setTextContentSize((int) this.contentSize);
|
||||
view.setCustomImage(this.imageRes);
|
||||
view.setType(this.type);
|
||||
if (this.backgroundColor != null) {
|
||||
view.setBackgroundColor(this.backgroundColor);
|
||||
}
|
||||
view.setHide_milliseconds(this.hideDuration);
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 便捷静态方法 ====================
|
||||
/**
|
||||
* 创建成功提示视图
|
||||
* @param context 上下文
|
||||
* @param message 消息内容
|
||||
* @return SlideDownView实例
|
||||
*/
|
||||
public static SlideDownView createSuccess(Context context, String message) {
|
||||
return new Builder(context)
|
||||
.setTitle("成功")
|
||||
.setContent(message)
|
||||
.setType(0)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建错误提示视图
|
||||
* @param context 上下文
|
||||
* @param message 消息内容
|
||||
* @return SlideDownView实例
|
||||
*/
|
||||
public static SlideDownView createError(Context context, String message) {
|
||||
return new Builder(context)
|
||||
.setTitle("错误")
|
||||
.setContent(message)
|
||||
.setType(1)
|
||||
.build();
|
||||
}
|
||||
|
||||
// ==================== 原有代码 ====================
|
||||
// 动画相关属性
|
||||
private final boolean isExpanded = false;
|
||||
private float mTextTitleSize = 15f;
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1 +1 @@
|
|||
a2045434f48db13223558d34f56ece04
|
||||
cf37179c5451ef8f324f85b6b5d5a609
|
||||
|
|
@ -1 +1 @@
|
|||
a027bd33d35a1504db4b61c39a4c387d3105b777
|
||||
0c2d562a65249d77b06a7aaf947961f5514357e2
|
||||
|
|
@ -1 +1 @@
|
|||
9e091b3209186276cbf95c138aa0af4e2dab4d0c46c23b45b9e493c3529c202e
|
||||
cd47b4b04dde3e9b942c69a93c5423e9f1161d72e4359cb1128263ec4ae32cee
|
||||
|
|
@ -1 +1 @@
|
|||
1a20b13e8ffe4b235e04ac474560d085e37bc71dfc50dffcd9f5b15c4a3cb3eea4badc5e9617cbfe91d5ea23136d47f6666f29fb4c6bd7dc83721c5782fb8204
|
||||
e3bb60f0b568365870f244bb79152d5158a2a193af8a9f7d4036a88774ebbb545cf51f243971e84acd2a622f197c5201f39bd95acab27f418f1234800445bd21
|
||||
|
|
@ -10,6 +10,6 @@
|
|||
<version>1.0.1</version>
|
||||
<version>1.1.0</version>
|
||||
</versions>
|
||||
<lastUpdated>20260106080444</lastUpdated>
|
||||
<lastUpdated>20260106061234</lastUpdated>
|
||||
</versioning>
|
||||
</metadata>
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
f2298a4dbfbde71af7355caa9b559c98
|
||||
5066a6b0dbb210a54474e49028391787
|
||||
|
|
@ -1 +1 @@
|
|||
462dd14aeadd7bf2272453e77e5b89d63d4a810e
|
||||
94ce02e02754089b391ea71049e474019d6c6efc
|
||||
|
|
@ -1 +1 @@
|
|||
5659a424a210627ed787d9d14780537f6b391d8874a58237ffc97a5a13153f9d
|
||||
1d26aae6c51048f59018f2ff94185aa2ec6749a76f59267bd8e79c08ba0d2929
|
||||
|
|
@ -1 +1 @@
|
|||
2f94512db1150b949af704251fb009e6636b6ab84b0c38998f6e6f4b93da018d65952655c8c29d4ad2a20e7049158038d4a2219298c0024d9a8e3268fec401ad
|
||||
9f5af0fe82b06ba0ae1a118053a5326bdd17b7f21f4188265e91d49a472e51f5dde812e851f2eabc6da3a4e3fb21f542068b7c879b9767ff472278bf03b23722
|
||||
Loading…
Reference in New Issue