当前位置: 代码迷 >> Android >> Android AlertDialog包含EditText,软键盘不能弹出的解决办法
  详细解决方案

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

热度:24   发布时间:2016-04-27 22:56:15.0
Android AlertDialog包含EditText,软键盘不能弹出的解决方法
AlertDialog包含EditText,软键盘不能弹出的解决方法


[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]


  相关解决方案