HTC WildFire 上的 SharedPreferences EditText 对话框被挤压
我在我的 Android 应用程序中以标准方式使用 SharedPreferences。在 HTC WildFire 设备(分辨率 240x320)上,显示虚拟键盘时 EditText 会被挤压。
有没有其他人遇到过这个,有解决办法吗?我已经被难住好几天了
我的代码/XML 非常简单:
public class PrefsActivity extends PreferenceActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
// don't display hidden preferences
getPreferenceScreen().removePreference(findPreference("hidden_prefs"));
}
}
我的preferences.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="User Preferences">
<EditTextPreference
android:key="profile"
android:title="Profile"
android:summary="Your profile name"
android:name="Profile"/>
<EditTextPreference
android:key="password"
android:title="Password"
android:summary="Your password"
android:name="Password"
android:password="true"/>
<EditTextPreference
android:name="Server"
android:summary="The server to use"
android:title="Server"
android:key="server"/>
<EditTextPreference
android:name="Secret"
android:summary="The server secret"
android:title="Secret"
android:password="true"
android:key="secret"/>
<CheckBoxPreference
android:title="On Demand"
android:defaultValue="true"
android:summary="Check to enable On Demand"
android:key="on_demand"/>
<ListPreference
android:title="Date"
android:summary="Set the type of date used"
android:key="date"
android:defaultValue="next"
android:entries="@array/prefs_date_keys"
android:entryValues="@array/prefs_date_values" />
</PreferenceCategory>
<PreferenceCategory android:key="hidden_prefs" android:title="Hidden Preferences">
<EditTextPreference
android:name="Last Project ID"
android:summary="The last Project ID"
android:title="Last Project ID"
android:key="last_project_id"
android:inputType="number"/>
<EditTextPreference
android:name="Fast Sync"
android:summary="Use Fast Sync"
android:title="Fast Sync"
android:key="fast_sync"
android:inputType="number"/>
</PreferenceCategory>
I'm using SharedPreferences in my Android app in the standard way. On the HTC WildFire device (resolution 240x320), the EditText is squashed up when the virtual keyboard is displayed.
Has anyone else come across this is there a solution? I've been stumped for days.
My code/XML is pretty straightforward:
public class PrefsActivity extends PreferenceActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
// don't display hidden preferences
getPreferenceScreen().removePreference(findPreference("hidden_prefs"));
}
}
And my preferences.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="User Preferences">
<EditTextPreference
android:key="profile"
android:title="Profile"
android:summary="Your profile name"
android:name="Profile"/>
<EditTextPreference
android:key="password"
android:title="Password"
android:summary="Your password"
android:name="Password"
android:password="true"/>
<EditTextPreference
android:name="Server"
android:summary="The server to use"
android:title="Server"
android:key="server"/>
<EditTextPreference
android:name="Secret"
android:summary="The server secret"
android:title="Secret"
android:password="true"
android:key="secret"/>
<CheckBoxPreference
android:title="On Demand"
android:defaultValue="true"
android:summary="Check to enable On Demand"
android:key="on_demand"/>
<ListPreference
android:title="Date"
android:summary="Set the type of date used"
android:key="date"
android:defaultValue="next"
android:entries="@array/prefs_date_keys"
android:entryValues="@array/prefs_date_values" />
</PreferenceCategory>
<PreferenceCategory android:key="hidden_prefs" android:title="Hidden Preferences">
<EditTextPreference
android:name="Last Project ID"
android:summary="The last Project ID"
android:title="Last Project ID"
android:key="last_project_id"
android:inputType="number"/>
<EditTextPreference
android:name="Fast Sync"
android:summary="Use Fast Sync"
android:title="Fast Sync"
android:key="fast_sync"
android:inputType="number"/>
</PreferenceCategory>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道这个答案很可能来得太晚了,但如果其他人正在寻找解决这个真正烦人问题的方法,这就是我解决它的方法,试图使其尽可能简单(对我来说,自定义布局是一个在这种情况下绝对不能):
使用此代码,屏幕键盘将显示在对话框按钮的顶部,但
EditText
仍然可见。I know this answer most likely comes too late, but in case anyone else is looking for a solution to this truly annoying problem, this is how I worked around it, trying to keep it as vanilla as possible (to me, custom layouts were a definite no-no in this case):
Using this code, the on-screen keyboard will be displayed on top of the dialog's buttons, but the
EditText
remains visible.两个建议:
1)一种更简单的方法,可能会也可能不会给你足够的空间,因为你的键盘看起来比标准的android键盘更高:在首选项活动中隐藏应用程序标题栏和android状态栏。这会将对话框向上移动一点。
2)更困难的方法是通过扩展 DialogPreference 或 EditTextPreference 来编写自己的自定义首选项控件,并为该控件定义自己的布局,该控件具有较小的标题或没有标题,或者可能较小的确定/取消按钮或其他内容。然后将该自定义控件放入您的preferences.xml中
Two suggestions:
1) the easier way which may or may not give you enough room as it looks like your keyboard is taller than the standard android one: Hide the application title bar and the android status bar in the preference activity. This will move the dialogbox up a little.
2) the harder way would be to write your own custom preference control by extending DialogPreference or EditTextPreference and define your own layout for that control that has a smaller or no title, or perhaps smaller ok/cancel buttons or something. then put that custom control in your preferences.xml
经过几次不同的尝试后,以下代码运行良好(带有编辑框的对话框不太好,但它很实用)。应自定义 EditTextPreference(还应更改具有首选项的资源文件)。 CustomTextPreference 应该有 3 个简单的构造函数。
公共类 CustomEditTextPreference 扩展 EditTextPreference
{
...
}
After a few different tries following code worked well (dialog with edit box is not so nice but it is functional). EditTextPreference should be customized (resource file with preferences should be changed also). CustomTextPreference should have trivial 3 constructors.
public class CustomEditTextPreference extends EditTextPreference
{
...
}