Android AlertDialog包含EditText,软键盘不能弹出的解决方法

[size=x-large][color=darkred]AlertDialog包含EditText,软键盘不能弹出的解决方法[/color][/size]


[size=large]public static void editContentDialog(final Context context) {
final AlertDialog dialog = new AlertDialog.Builder(context).create();
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout layout = (RelativeLayout)inflater.inflate(R.layout.define_dialog_2, null);
dialog.setView(layout);
dialog.show();
Window window = dialog.getWindow();
// *** 主要就是在这里实现这种效果的.
window.setContentView(R.layout.define_dialog_2);

RelativeLayout rlCancel = (RelativeLayout) window.findViewById(R.id.rl_left);
RelativeLayout rlBoundPhone = (RelativeLayout) window
.findViewById(R.id.rl_right);
TextView tvTitle = (TextView) window.findViewById(R.id.tv_dialog_title);
final EditText etContent = (EditText) window
.findViewById(R.id.et_content);
TextView tvLeft = (TextView) window.findViewById(R.id.tv_left);
TextView tvRight = (TextView) window.findViewById(R.id.tv_right);

tvTitle.setText("新建列表");
tvTitle.setVisibility(View.VISIBLE);
etContent.setTextSize(16.0f);
tvLeft.setText("取消");
tvRight.setText("保存");
rlCancel.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
dialog.dismiss();
}
});

rlBoundPhone.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.setCanceledOnTouchOutside(true);// 设置点击屏幕Dialog不消失
}[/size]


define_dialog_2.xml
[size=large]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="@drawable/corner_box_white_2" >

<TextView
android:id="@+id/tv_dialog_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:textColor="@color/black"
android:text="手机绑定"
android:visibility="visible"
android:textSize="20sp" />

<!-- <TextView
android:id="@+id/tv_dialog_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:gravity="center"
android:textColor="@color/black"
android:layout_below="@id/tv_dialog_title"
android:minHeight="40dp"
android:text="法杰拉尔家乐福吉安网络服务了解放军阿拉维"
android:textSize="20sp" /> -->
<EditText
android:id="@+id/et_content"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_below="@id/tv_dialog_title"
android:layout_marginTop="15dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:singleLine="true"
android:ellipsize="end"
android:textColor="@color/black"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="请输入新列表名称"
android:gravity="center"
android:text="猎人"
android:background="@drawable/corner_box_white_90"
/>

<View
android:id="@+id/view_line"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/et_content"
android:layout_marginTop="15dp"
android:background="@color/gray" />

<View
android:id="@+id/view_shuxian"
android:layout_width="1dp"
android:layout_height="45dp"
android:layout_below="@id/view_line"
android:layout_centerHorizontal="true" />

<RelativeLayout
android:id="@+id/rl_left"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_below="@id/view_line"
android:layout_toLeftOf="@id/view_shuxian"
android:background="@drawable/unicorn_left_bottom" >

<TextView
android:id="@+id/tv_left"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:textColor="@color/white"
android:textSize="20sp" />
</RelativeLayout>

<RelativeLayout
android:id="@+id/rl_right"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_below="@id/view_line"
android:layout_toRightOf="@id/view_shuxian"
android:background="@drawable/unicorn_right_bottom" >

<TextView
android:id="@+id/tv_right"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:textColor="@color/white"
android:textSize="20sp" />
</RelativeLayout>
</RelativeLayout>

</RelativeLayout>
[/size]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值