AlertDialog 自定义样式

废话不多说了,只是做个笔记,以后忘了才可以查看下,我一般都不不去记这些方法的,知道了就好,要用的时候查下就可以了。


关键性代码:

/**
	 * 用户名或密码错误的弹窗
	 * 网络状况不好的弹窗
	 */
	public void show_login_error(String err_text){
		final AlertDialog dlg = new AlertDialog.Builder(this).create();
		 dlg.show();
		 Window window = dlg.getWindow();
		// *** 主要就是在这里实现这种效果的.
		// 设置窗口的内容页面,login_error_butt.xml文件中定义view内容
		 window.setContentView(R.layout.pupwindow_login_error);
		 Button login_err = (Button) window.findViewById(R.id.login_error_butt);
		 TextView text=(TextView) window.findViewById(R.id.login_error_text);
		 text.setText(err_text);
		 login_err.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(final View v) {
					dlg.dismiss();
				}
			});
	}

你要显示的布局文件

pupwindow_login_error.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/login_popup_bg"
    android:orientation="vertical" >
    <TextView
        android:id="@+id/login_error_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:gravity="center_horizontal"
        android:text="账号或密码错误"
        android:textSize="18sp"
        />
    <View 
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:layout_marginRight="5dp"
        android:layout_marginLeft="5dp"
        android:background="#d2d2d2"
        />
	<Button 
	    android:id="@+id/login_error_butt"
	    android:layout_width="match_parent"
	    android:layout_height="wrap_content"
	    android:gravity="center_horizontal|center_vertical"
	    android:text="确定"
	    android:background="@null"
	    />
</LinearLayout>


转载于:https://my.oschina.net/u/141726/blog/407884

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值