标签:dialog
1.UpdateDialog
/**
* 版本更新的dialog}
2.dialog_update.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_height="150dp"
android:orientation="vertical"
android:layout_gravity="center_horizontal"
android:background="@color/lightblue"
android:layout_marginBottom="@dimen/h35">
<TextView
android:id="@+id/dialogMsg"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text=""
android:gravity="center"
android:textSize="18sp"
android:textColor="@color/white"/>
<Button
android:id="@+id/btUpLoad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="@color/white"
android:textSize="18sp"
android:layout_gravity="center"
android:background="@drawable/bt_blue_selector"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:layout_marginBottom="16dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
/>
</LinearLayout>
3.使用
int serVerCode=2;
try {
int verCode=ac.getPackageManager().getPackageInfo(ac.getPackageName(), 0).versionCode;
final UpdateDialog updateDialog=new UpdateDialog(ac, R.style.dialog_style);
Window mwWindow=updateDialog.getWindow();
WindowManager.LayoutParams lp=mwWindow.getAttributes();
mwWindow.setGravity(Gravity.BOTTOM);
mwWindow.setAttributes(lp);
if(serVerCode>verCode){
updateDialog.setMsg(getResources().getString(R.string.update_mes_new));
updateDialog.setBtText(getResources().getString(R.string.update_now));
updateDialog.setOnBtnclick(new BtnClickListener() {
@Override
public void onClick() {
ToastUtils.show(ac, "正在更新。。。");
updateDialog.dismiss();
}
});
}else{
String vername=ac.getPackageManager().getPackageInfo(ac.getPackageName(), 0).versionName;
updateDialog.setMsg(getString(R.string.update_msg_now_is_new)+vername);
updateDialog.setBtText(getString(R.string.update_sure));
updateDialog.setOnBtnclick(new BtnClickListener() {
@Override
public void onClick() {
updateDialog.dismiss();
}
});
}
updateDialog.show();
} catch (NameNotFoundException e) {
e.printStackTrace();
}
标签:dialog
原文地址:http://blog.csdn.net/u013042707/article/details/45307731