方法:
在EditTxt的外层父控件添加两个属性就行
android:focusable="true"
android:focusableInTouchMode="true"
android:focusable="true" :意思是指布局能够获取到焦点。
android:focusableInTouchMode="true":意思是指布局能通过touch获得焦点。
例如:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal">
<EditText
android:id="@+id/pwd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入新密码"
android:inputType="textPassword"
android:singleLine="true"
android:maxLength="18" />
</LinearLayout>
打开这个activity布局,会发现一开始并不会弹出键盘,当点击了EditText,就可以获取到焦点,弹出键盘。