android新闻页面布局,Android 类似新闻界面评论框

此博客主要展示了Android中初始化评论弹窗的代码。通过创建Dialog对象,设置其布局、位置和大小等属性,实现弹窗显示。还对输入框和发布按钮添加了交互逻辑,如提交后清空内容、监听输入框文字变化等,同时包含软键盘显示与隐藏操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/**

* 初始化dialog

*/

private void showDialog() {

Dialog dialog =new Dialog(this);

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

dialog.setContentView(R.layout.popu_comment);

Window dialogWindow = dialog.getWindow();

dialogWindow.setGravity(Gravity.BOTTOM);

dialogWindow.getDecorView().setPadding(0, 0, 0, 0);

WindowManager.LayoutParams lp = dialogWindow.getAttributes();

lp.width = WindowManager.LayoutParams.MATCH_PARENT;

lp.height = WindowManager.LayoutParams.WRAP_CONTENT;

dialogWindow.setAttributes(lp);

dialog.show();

//查找控件

EditText edComment = dialog.findViewById(R.id.ed_comment);

TextView btnFaBu = dialog.findViewById(R.id.btn_fabu_pl);

btnFaBu.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

dialog.dismiss();

//提交之后要讲str清空

str ="";

//展示框复原

tvContent.setText("请输入您的评论内容");

}

});

//判断有没有编辑过评论内容 如果编辑过就在显示出来

if (!TextUtils.isEmpty(str)) {

edComment.setText(str);

edComment.setSelection(str.length());//将光标移至文字末尾

}

//添加监听

edComment.addTextChangedListener(new TextWatcher() {

@Override

public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

@Override

public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

@Override

public void afterTextChanged(Editable editable) {

str =edComment.getText().toString();

tvContent.setText(str);

}

});

showSoft();

dismissSofo(dialog);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值