自定义的AlertDialog获取软键盘和editext中的内容

/*弹框布局展示*/
loginalert= new AlertDialog.Builder(MainActivity.this); 
textEntryView = getLayoutInflater().inflate(R.layout.loginalertdialoglayout, null);
loginalert.setView(textEntryView);
/*编辑框的定义*/
account=(EditText)textEntryView.findViewById(R.id.account);
password=(EditText)textEntryView.findViewById(R.id.password);
System.out.println("哈哈!你好的啦~");
loginalert.setPositiveButton("确定", new android.content.DialogInterface.OnClickListener()
{
//@Override
public void onClick(DialogInterface dialog, int which)
{
studentpassword=password.getText().toString();
studentaccount=account.getText().toString();
System.out.println(studentaccount+"studentaccount"+studentpassword+"studentpassword");
try {
if(studentaccount.equals("")||studentpassword.equals(""))
{
Toast.makeText(getApplicationContext(), "请填入账号和密码",
Toast.LENGTH_LONG).show();
}
else if(studentaccount!=""&&studentpassword!="")
{
MainActivity.this.information();
}
} catch (ClientProtocolException e) { 
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}});
loginalert.setNegativeButton("取消", new android.content.DialogInterface.OnClickListener() {


@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.dismiss();


}
});
loginalert.create().show(); 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的自定义AlertDialog布局示例,其包含一个标题、一个消息、两个按钮: ```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_height="wrap_content" android:orientation="vertical" android:padding="16dp"> <TextView android:id="@+id/alert_dialog_title" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="这是自定义AlertDialog" android:textSize="18sp" android:textColor="@color/colorPrimary"/> <TextView android:id="@+id/alert_dialog_message" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:text="这是自定义AlertDialog的消息内容" android:textSize="16sp"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginTop="16dp"> <Button android:id="@+id/alert_dialog_cancel" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="取消"/> <Button android:id="@+id/alert_dialog_confirm" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="确定"/> </LinearLayout> </LinearLayout> ``` 这个布局包含一个LinearLayout,其包含一个标题和一个消息的TextView,以及两个按钮的LinearLayout。注意,按钮使用了layout_weight属性,让它们均分父布局的宽度。在代码,你可以通过findViewById()方法找到这些控件,设置它们的文本、图标、事件监听器等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值