android - HTC WildFire 上的 SharedPreferences EditText 对话框被挤压

标签 android sharedpreferences htc-android

我正在我的 Android 应用程序中以标准方式使用 SharedPreferences。在 HTC WildFire 设备(分辨率 240x320)上,显示虚拟键盘时 EditText 会被挤压。

有没有其他人遇到过这个问题,有解决办法吗?我已经被难住好几天了。

My SharedPreferences activity on the HTC WildFire

我的代码/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>

最佳答案

我知道这个答案很可能来得太晚了,但如果其他人正在寻找这个真正烦人的问题的解决方案,这就是我解决它的方法,试图使其尽可能简单(对我来说,自定义在这种情况下,布局是明确的禁忌):

public class MyEditTextPreference extends EditTextPreference
{
    public MyEditTextPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void showDialog(Bundle bundle) {
        super.showDialog(bundle);

        Dialog dialog = getDialog();
        if(dialog != null) {
            Window window = dialog.getWindow();
            window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE |
                WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        }
    }
}

使用此代码,屏幕键盘将显示在对话框按钮的顶部,但 EditText 仍然可见。

关于android - HTC WildFire 上的 SharedPreferences EditText 对话框被挤压,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6087131/

相关文章:

android - HTC One X 和 Android 在 eclipse 上调试

android - 标准 Intent URI 损坏?

java - 在个人资料中编辑显示名称时如何存储重复共享首选项

android - 如何根据Android中的共享首选项显示来自MySQL的数据?

java - 重写非 Activity 类中的方法,Android

android - 如何找到 Android 2.3.3 平台的源代码?

android - 共享首选项-选择铃声基本实现

4G/LTE 上的 Android HttpClient OOM (HTC Thunderbolt)

安卓应用-登录账号

android - 使用微调器时如何从 TextView 中获取文本