EditText 默认不获取焦点,弹出软键盘布局变形解决方案

关于弹出软键盘布局变形解决方案:

在androidMainfest.xml文件中在此Activity中写入 android:windowSoftInputMode="adjustPan"

在实际开发中,有的页面用到Edittext控件,这时候进入该页面可能会自动弹出输入法

这么显示不太友好,所以需要设置一下让Edittext默认不自动获取焦点。在网上查资料解决办法如下:

在EditText的父级控件中找一个,设置成

android:focusable="true"  
android:focusableInTouchMode="true"

<LinearLayout
	android:layout_width="match_parent"
	android:layout_height="74dp"
	android:focusable="true"
	android:focusableInTouchMode="true"
	android:gravity="center_vertical"
	android:orientation="horizontal"
	android:paddingLeft="20dip"
	android:paddingRight="20dip" >

	<TextView
		style="@style/BillDetailLabel"
		android:text="@string/takecar_car_kilometre" />

	<EditText
		android:id="@+id/my_bill_detail_takecar_car_kilometre_content"
		style="@style/BillDetailContent"
		android:layout_width="0dp"
		android:layout_marginLeft="10dp"
		android:layout_weight="1"
		android:gravity="left"
		android:inputType="number"
		android:maxLength="9" />

	<TextView
		style="@style/BillDetailLabel"
		android:layout_marginLeft="2dp"
		android:text="@string/kilometre" />

	<Button
		android:id="@+id/my_bill_detail_takepic_btn"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_marginLeft="10dp"
		android:background="@drawable/my_bill_detail_camera_icon_selector" />
</LinearLayout>

  开始会自动获取焦点的元素是 my_bill_detail_takecar_car_kilometre_content

当我在该 EditText 的父节点 LinearLayout 上面设置了

android:focusable="true"
android:focusableInTouchMode="true"

之后就不会启动这个画面默认启动输入法了

原文地址:https://www.cnblogs.com/spring87/p/4419849.html