获取 AlertDialog自定义的布局 的控件,进行点击,修改文字

获取 AlertDialog自定义的布局 的控件,进行点击,修改文字


View view = LayoutInflater.from(activity).inflate(R.layout.dialog_show, null);
LinearLayout wx_pay = view.findViewById(R.id.wx_pay);
LinearLayout alipy_pay = view.findViewById(R.id.alipy_pay);
final android.app.AlertDialog dialog = new AlertDialog.Builder(activity).create();
dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
    @Override
    public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event)
    {
        if (keyCode == KeyEvent.KEYCODE_BACK||keyCode == KeyEvent.KEYCODE_SEARCH)
        {
            return true;
        }
        else
        {
            return false; //默认返回 false
        }
    }
});
dialog.setCancelable(false);
dialog.show();
dialog.getWindow().clearFlags(
        WindowManager.La

  • 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、付费专栏及课程。

余额充值