Skip to content

Commit

Permalink
v1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
SiberiaDante committed Nov 16, 2017
1 parent 898bb81 commit 0f092fa
Show file tree
Hide file tree
Showing 16 changed files with 433 additions and 114 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ Error:Execution failed for task ':app:processDebugResources'. > com.android.ide.
```
解决方法:COMPILE_SDK_VERSION>=26
### 版本更新说明:
* v1.0.2(未发布)
* CustomDialog 增加支持添加一个EditText
* v1.0.2:
* CustomDialog 增加支持动态设置View属性

[CustomDialog]:https://github.com/SiberiaDante/CustomDialog/blob/0e3849999b7ed3398255b1312fa28d7d38b23306/customdialoglib/src/main/java/com/siberiadante/customdialoglib/CustomDialog.java
[EditDialog]:https://github.com/SiberiaDante/CustomDialog/blob/0e3849999b7ed3398255b1312fa28d7d38b23306/customdialoglib/src/main/java/com/siberiadante/customdialoglib/EditDialog.java
Expand Down
73 changes: 39 additions & 34 deletions app/src/main/java/com/siberiadante/customdialog/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.siberiadante.customdialog;

import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

Expand All @@ -12,6 +14,8 @@
import com.siberiadante.customdialoglib.EditDialog;
import com.siberiadante.customdialoglib.EnsureDialog;

import java.util.List;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private EnsureDialog ensureDialog;

Expand All @@ -30,7 +34,7 @@ private void initView() {
findViewById(R.id.btn_bottom_popup_widow).setOnClickListener(this);
findViewById(R.id.btn_edit_dialog).setOnClickListener(this);
findViewById(R.id.btn_custom_dialog).setOnClickListener(this);
findViewById(R.id.btn_custom_edit_dialog).setOnClickListener(this);
findViewById(R.id.btn_sd_custom_dialog).setOnClickListener(this);
}

@Override
Expand All @@ -57,9 +61,8 @@ public void onClick(View view) {
case R.id.btn_custom_dialog:
showCustomDialog();
break;
case R.id.btn_custom_edit_dialog:

showCustomEditDialog();
case R.id.btn_sd_custom_dialog:
showSDCustomEditDialog();
break;
}
}
Expand Down Expand Up @@ -120,15 +123,15 @@ public void onClick(int which) {
private void showEnsureDialogOne() {
ensureDialog = new EnsureDialog(this).builder()
.setGravity(Gravity.CENTER)//默认居中,可以不设置
.setTitle("这里是一个标题", getResources().getColor(R.color.black))//可以不设置标题颜色,默认系统颜色
.setTitle("这里是一个标题", getResources().getColor(R.color.sd_color_black))//可以不设置标题颜色,默认系统颜色
.setCancelable(false)
.setNegativeButton("取消", new View.OnClickListener() {//可以选择设置颜色和不设置颜色两个方法
@Override
public void onClick(View view) {

}
})
.setPositiveButton("确认", getResources().getColor(R.color.red), new View.OnClickListener() {//可以选择设置颜色和不设置颜色两个方法
.setPositiveButton("确认", getResources().getColor(R.color.sd_color_red), new View.OnClickListener() {//可以选择设置颜色和不设置颜色两个方法
@Override
public void onClick(View view) {
ensureDialog.dismiss();
Expand All @@ -142,7 +145,7 @@ public void onClick(View view) {
private void showEnsureDialogTwo() {
ensureDialog = new EnsureDialog(this).builder()
.setGravity(Gravity.CENTER)//默认居中,可以不设置
.setTitle("这里是一个标题", getResources().getColor(R.color.black))//可以不设置标题颜色,默认系统颜色
.setTitle("这里是一个标题", getResources().getColor(R.color.sd_color_black))//可以不设置标题颜色,默认系统颜色
.setSubTitle("这是一个副标题")
.setCancelable(false)
.setNegativeButton("取消", new View.OnClickListener() {//可以选择设置颜色和不设置颜色两个方法
Expand All @@ -151,7 +154,7 @@ public void onClick(View view) {

}
})
.setPositiveButton("确认", getResources().getColor(R.color.red), new View.OnClickListener() {//可以选择设置颜色和不设置颜色两个方法
.setPositiveButton("确认", getResources().getColor(R.color.sd_color_red), new View.OnClickListener() {//可以选择设置颜色和不设置颜色两个方法
@Override
public void onClick(View view) {
ensureDialog.dismiss();
Expand All @@ -165,7 +168,7 @@ public void onClick(View view) {
private void showEnsureDialogThree() {
ensureDialog = new EnsureDialog(this).builder()
.setGravity(Gravity.CENTER)//默认居中,可以不设置
.setTitle("这里是一个标题", getResources().getColor(R.color.black))//可以不设置标题颜色,默认系统颜色
.setTitle("这里是一个标题", getResources().getColor(R.color.sd_color_black))//可以不设置标题颜色,默认系统颜色
.setIncon(R.mipmap.tip_icon)//不设置图标,默认没有图标
.setCancelable(false)
.setNegativeButton("取消", new View.OnClickListener() {//可以选择设置颜色和不设置颜色两个方法
Expand All @@ -174,7 +177,7 @@ public void onClick(View view) {

}
})
.setPositiveButton("确认", getResources().getColor(R.color.red), new View.OnClickListener() {//可以选择设置颜色和不设置颜色两个方法
.setPositiveButton("确认", getResources().getColor(R.color.sd_color_red), new View.OnClickListener() {//可以选择设置颜色和不设置颜色两个方法
@Override
public void onClick(View view) {
ensureDialog.dismiss();
Expand All @@ -188,7 +191,7 @@ public void onClick(View view) {
private void showEnsureDialogFour() {
ensureDialog = new EnsureDialog(this).builder()
.setGravity(Gravity.CENTER)//默认居中,可以不设置
.setTitle("这里是一个标题", R.color.black)//可以不设置标题颜色,默认系统颜色
.setTitle("这里是一个标题", R.color.sd_color_black)//可以不设置标题颜色,默认系统颜色
.setCancelable(false)
.setCenterButton("取消", new View.OnClickListener() {//可以选择设置颜色和不设置颜色两个方法
@Override
Expand All @@ -201,41 +204,43 @@ public void onClick(View view) {
}

private void showCustomDialog() {
final CustomDialog customDialog = new CustomDialog(this, R.layout.dialog_layout, new int[]{R.id.dialog_sure}, true, Gravity.CENTER);
customDialog.setOnDialogItemClickListener(new CustomDialog.OnCustomDialogItemClickListener() {
@Override
public void OnCustomDialogItemClick(CustomDialog dialog, View view) {
// customDialog.dismiss();
Toast.makeText(MainActivity.this, "确定按钮被点击了", Toast.LENGTH_LONG).show();
}
});
final CustomDialog customDialog = new CustomDialog(this, R.layout.dialog_sd_custom);
customDialog.show();

}

private void showCustomEditDialog() {
/**
* 这种方式使用中的缺陷就是需要资源id需要一一对应
*/
private void showSDCustomEditDialog() {
final CustomDialog customDialog = new CustomDialog(this,
R.layout.dialog_edit,
new int[]{R.id.btn_cancel,R.id.btn_sure},
R.id.edt_content,
R.layout.dialog_sd_custom,
new int[]{R.id.btn_cancel, R.id.btn_sure, R.id.edt_content, R.id.edt_sub_content},
0,
true,
false,
false,
Gravity.CENTER);
customDialog.setOnDialogItemClickListener(new CustomDialog.OnCustomDialogItemClickListener() {
@Override
public void OnCustomDialogItemClick(CustomDialog dialog, View view) {
switch (view.getId()) {
case R.id.btn_cancel:
break;
case R.id.btn_sure:

break;
}
switch (view.getId()) {
case R.id.btn_cancel:
customDialog.dismiss();
break;
case R.id.btn_sure:

break;
}
}
});

customDialog.show();
final EditText editText = customDialog.getEditText();
editText.setHint("这是一个提示");
final List<View> viewList = customDialog.getViews();
final Button btnSure = (Button) viewList.get(1);
btnSure.setTextColor(ContextCompat.getColor(this, R.color.colorGray));
final EditText edtContent = (EditText) viewList.get(2);
final EditText edtSubContent = (EditText) viewList.get(3);
edtContent.setHint("这是一个主内容");
edtSubContent.setHint("这是一个副内容");
}

@Override
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@
android:id="@+id/btn_custom_dialog"
style="@style/MainButton"
android:text="自定义布局的Dialog" />


<Button
android:id="@+id/btn_custom_edit_dialog"
android:id="@+id/btn_sd_custom_dialog"
style="@style/MainButton"
android:text="自定义布局支持一个EditText的Dialog" />
android:text="自定义布局支持各种自定义Dialog" />
</LinearLayout>
</ScrollView>
</LinearLayout>
6 changes: 3 additions & 3 deletions app/src/main/res/layout/dialog_edit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
android:layout_marginBottom="28dp"
android:text="请输入您的内容"
android:gravity="center"
android:textColor="@color/black"
android:textColor="@color/sd_color_black"
android:textSize="16sp"
android:layout_height="wrap_content" />
<View
android:background="@color/black"
android:background="@color/sd_color_black"
android:layout_marginStart="15dp"
android:layout_width="match_parent"
android:layout_height="1dp"
Expand All @@ -33,7 +33,7 @@
android:layout_marginStart="15dp"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/black"
android:background="@color/sd_color_black"
android:layout_marginEnd="15dp"/>
<LinearLayout
android:layout_width="match_parent"
Expand Down
98 changes: 98 additions & 0 deletions app/src/main/res/layout/dialog_sd_custom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bac_white_one"
android:gravity="center"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:drawableLeft="@mipmap/icon_tips"
android:gravity="center"
android:text="支持各种布局,各种自定义属性哦!"
android:textSize="11sp" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="28dp"
android:layout_marginTop="18dp"
android:gravity="center"
android:text="请输入您的内容"
android:textColor="@color/colorBlack"
android:textSize="16sp" />

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginEnd="15dp"
android:layout_marginStart="15dp"
android:background="@color/colorGray" />

<EditText
android:id="@+id/edt_content"
style="@style/CustomEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:gravity="center"
android:textColor="@color/colorBlack"
android:textSize="13sp" />

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginEnd="15dp"
android:layout_marginStart="15dp"
android:background="@color/colorGray" />

<EditText
android:id="@+id/edt_sub_content"
style="@style/CustomEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:gravity="center"
android:textColor="@color/colorBlack"
android:textSize="13sp" />

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginEnd="15dp"
android:layout_marginStart="15dp"
android:background="@color/colorGray" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">

<Button
android:id="@+id/btn_cancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:text="取消"
android:textColor="@color/colorBlack"
android:textSize="16sp" />

<Button
android:id="@+id/btn_sure"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:clickable="false"
android:text="确定"
android:textColor="@color/colorBlack"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
Binary file added app/src/main/res/mipmap-xhdpi/icon_tips.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="colorBlack">#000000</color>
<color name="colorGray">#767474</color>
</resources>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'

classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
7 changes: 4 additions & 3 deletions customdialoglib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
apply plugin: 'com.android.library'

apply plugin: 'com.github.dcendents.android-maven'
group='com.github.SiberiaDante'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"

defaultConfig {
minSdkVersion 14
targetSdkVersion 26
versionCode 1
versionName "1.0"
versionCode 2
versionName "1.1"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
Loading

0 comments on commit 0f092fa

Please sign in to comment.