Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android-AlertView #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions alertview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 14 additions & 0 deletions alertview/src/main/java/com/bigkoo/alertview/AlertView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/bigkoo/alertviewdemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ public void alertShow6(View view) {
this, AlertView.Style.ActionSheet, this).show();
}

public void alertShow7(View view) {
new AlertView(null, "内容", null, null, new String[]{"确定"}, this, AlertView.Style.Alert, this).show();
}

public void alertShowExt(View view) {
mAlertViewExt.show();
}
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
android:layout_marginTop="5dp"
android:layout_height="50dp"
android:onClick="alertShow3"/>
<Button android:text="hey,alert no title !!!click here~~~" android:layout_width="match_parent"
android:layout_marginTop="5dp"
android:layout_height="50dp"
android:onClick="alertShow7"/>
<Button android:text="hey,actionsheet !!!click here~~~" android:layout_width="match_parent"
android:layout_marginTop="5dp"
android:layout_height="50dp"
Expand Down