Android自定义EditText通过键盘打开和关闭来调整大小
我为我的 EditText 字段实现了自定义背景,因为我认为 EditText 的默认值太高且太高。填充太多。无论如何,新的 EditText 可绘制背景显示正常,但是当我打开键盘时,字段会稍微缩小,而当我关闭键盘时,字段会扩展至原始(自定义)大小。这种行为必须以某种方式被重写,而我只是没有偶然发现。有人可以帮忙吗?我已经阅读了 Android 开发网站上的 IMEOptions 文章,但我并没有真正想到可以解决这个问题。谢谢!
这是我的 EditText - 每个 EditText 都有自己的布局,因为我需要在字段之间添加填充:
<LinearLayout android:layout_height="wrap_content"
android:layout_width="fill_parent" android:orientation="vertical" android:paddingBottom="5dip" android:paddingLeft="3dip" android:paddingRight="3dip">
<EditText android:id="@+id/join_firstName"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="@drawable/joinedittextselector" android:padding="5dip" /> <!-- android:layout_weight="1" -->
</LinearLayout>
这是我的选择器:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="@drawable/join_field_bg_default" />
<item android:state_window_focused="false" android:state_enabled="false"
android:drawable="@drawable/join_field_bg_default" />
<item android:state_pressed="true" android:drawable="@drawable/join_field_bg_default" />
<item android:state_enabled="true" android:state_focused="true"
android:drawable="@drawable/join_field_bg_selected" />
<item android:state_enabled="true" android:drawable="@drawable/join_field_bg_default" />
<item android:state_focused="true" android:drawable="@drawable/join_field_bg_selected" />
<item android:drawable="@drawable/join_field_bg_default" />
我已经尝试过使用 editText 的活动的 android:windowSoftInputMode 设置的 adjustmentResize 和 adjustmentPan ,但两者都不起作用。再次感谢您对此的任何建议!
i implemented a custom background for my EditText fields because i think the defaults for the EditTexts are too tall & have too much padding. anyway, the new EditText drawable backgrounds are displaying fine, BUT the fields shrink slightly when i open the keyboard and expand to their original (custom) size when i close the keyboard. this behavior must be overridable in some way that i just haven't stumbled across. can anyone help, please? I've read the IMEOptions article at the dev android site and nothing there really jumps out at me at as a possible solution to this problem. thanks!
here is my EditText - each EditText is in its own layout because i needed to add padding BETWEEN the fields:
<LinearLayout android:layout_height="wrap_content"
android:layout_width="fill_parent" android:orientation="vertical" android:paddingBottom="5dip" android:paddingLeft="3dip" android:paddingRight="3dip">
<EditText android:id="@+id/join_firstName"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="@drawable/joinedittextselector" android:padding="5dip" /> <!-- android:layout_weight="1" -->
</LinearLayout>
here is my selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="@drawable/join_field_bg_default" />
<item android:state_window_focused="false" android:state_enabled="false"
android:drawable="@drawable/join_field_bg_default" />
<item android:state_pressed="true" android:drawable="@drawable/join_field_bg_default" />
<item android:state_enabled="true" android:state_focused="true"
android:drawable="@drawable/join_field_bg_selected" />
<item android:state_enabled="true" android:drawable="@drawable/join_field_bg_default" />
<item android:state_focused="true" android:drawable="@drawable/join_field_bg_selected" />
<item android:drawable="@drawable/join_field_bg_default" />
i've tried adjustResize and adjustPan for the android:windowSoftInputMode setting of the activity that the EditText is used in and neither have worked. thanks again for any advice on this!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能必须提供在 xml 资源中定义它们的各种状态的图像。人们经常对按钮这样做。
You would probably have to provide images for the various states defining them in an xml resource. People do this a lot for buttons.