From b920e3531c6d03a069b7e41bdc90686e57207ab4 Mon Sep 17 00:00:00 2001 From: ng Date: Fri, 21 Aug 2015 12:13:38 +0800 Subject: [PATCH 1/2] =?UTF-8?q?Android-AlertView=20*=201.0.1=20*=20?= =?UTF-8?q?=E4=B8=8D=E6=98=BE=E7=A4=BA=E6=A0=87=E9=A2=98=E6=97=B6=E4=BB=A4?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E5=9E=82=E7=9B=B4=E5=B1=85=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- alertview/build.gradle | 6 +++--- .../main/java/com/bigkoo/alertview/AlertView.java | 14 ++++++++++++++ app/build.gradle | 6 +++--- .../com/bigkoo/alertviewdemo/MainActivity.java | 4 ++++ app/src/main/res/layout/activity_main.xml | 4 ++++ 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/alertview/build.gradle b/alertview/build.gradle index 6349e71..e5fe5ef 100644 --- a/alertview/build.gradle +++ b/alertview/build.gradle @@ -6,13 +6,13 @@ version = "1.0.0" android { compileSdkVersion 21 - buildToolsVersion "20.0.0" + buildToolsVersion "21.1.2" defaultConfig { minSdkVersion 14 targetSdkVersion 21 - versionCode 1 - versionName "1.0" + versionCode 2 + versionName "1.0.1" } buildTypes { release { diff --git a/alertview/src/main/java/com/bigkoo/alertview/AlertView.java b/alertview/src/main/java/com/bigkoo/alertview/AlertView.java index bf1dc99..c63895d 100644 --- a/alertview/src/main/java/com/bigkoo/alertview/AlertView.java +++ b/alertview/src/main/java/com/bigkoo/alertview/AlertView.java @@ -2,6 +2,7 @@ import android.app.Activity; import android.content.Context; +import android.content.res.Resources; import android.graphics.Typeface; import android.view.Gravity; import android.view.LayoutInflater; @@ -132,16 +133,29 @@ protected void initHeaderView(ViewGroup viewGroup){ //标题和消息 TextView tvAlertTitle = (TextView) viewGroup.findViewById(R.id.tvAlertTitle); TextView tvAlertMsg = (TextView) viewGroup.findViewById(R.id.tvAlertMsg); + + //获取msg部分的bottom margin + int dimenMsgBottomMargin = 0; + if(title != null) { tvAlertTitle.setText(title); }else{ tvAlertTitle.setVisibility(View.GONE); + try { + //标题不可见时顶部增加padding与底部margin相同保证消息垂直居中 + dimenMsgBottomMargin = context.getResources().getDimensionPixelSize(R.dimen.marginBottom_alert_msg); + } + catch (Resources.NotFoundException e) { + dimenMsgBottomMargin = 0; + } } if(msg != null) { tvAlertMsg.setText(msg); }else{ tvAlertMsg.setVisibility(View.GONE); } + + tvAlertMsg.setPadding(0, dimenMsgBottomMargin, 0, 0); } protected void initListView(){ ListView alertButtonListView = (ListView) contentContainer.findViewById(R.id.alertButtonListView); diff --git a/app/build.gradle b/app/build.gradle index f78b296..2b7b372 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,14 +2,14 @@ apply plugin: 'com.android.application' android { compileSdkVersion 21 - buildToolsVersion "20.0.0" + buildToolsVersion "21.1.2" defaultConfig { applicationId "com.bigkoo.alertviewdemo" minSdkVersion 14 targetSdkVersion 21 - versionCode 1 - versionName "1.0" + versionCode 2 + versionName "1.0.1" } buildTypes { release { diff --git a/app/src/main/java/com/bigkoo/alertviewdemo/MainActivity.java b/app/src/main/java/com/bigkoo/alertviewdemo/MainActivity.java index 66585c8..a9839b2 100644 --- a/app/src/main/java/com/bigkoo/alertviewdemo/MainActivity.java +++ b/app/src/main/java/com/bigkoo/alertviewdemo/MainActivity.java @@ -75,6 +75,10 @@ public void alertShow6(View view) { this, AlertView.Style.ActionSheet, this).show(); } + public void alertShow7(View view) { + new AlertView(null, "内容", null, new String[]{"确定"}, null, this, AlertView.Style.Alert, this).show(); + } + public void alertShowExt(View view) { mAlertViewExt.show(); } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 3baf8f5..fde3854 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -18,6 +18,10 @@ android:layout_marginTop="5dp" android:layout_height="50dp" android:onClick="alertShow3"/> +