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]

android:layout_width="match_parent"
android:layout_height="match_parent" >

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" >

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" />


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"
/>

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" />

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

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" >

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" />


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" >

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" />



[/size]

你可能感兴趣的:(android)