2

Android アプリで SharedPreferences を標準的な方法で使用しています。HTC WildFire デバイス (解像度 240x320) では、仮想キーボードが表示されると EditText が押しつぶされます。

他の誰かがこれに遭遇しましたか?解決策はありますか? 私は何日も困惑しています。

HTC WildFire での私の SharedPreferences アクティビティ

私のコード/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>

4

3 に答える 3

2

この答えが遅すぎる可能性が高いことはわかっていますが、他の誰かがこの本当に厄介な問題の解決策を探している場合に備えて、これが私がそれを回避し、できるだけバニラに保つように努めた方法です (私にとって、カスタムレイアウトはこの場合、明確なノーノー):

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ままになります。

于 2011-12-12T21:44:57.513 に答える
1

次のコードを数回試した後、うまくいきました(編集ボックスのあるダイアログはあまり良くありませんが、機能しています)。EditTextPreference をカスタマイズする必要があります (設定を含むリソース ファイルも変更する必要があります)。CustomTextPreference には、簡単な 3 つのコンストラクターが必要です。

public class CustomEditTextPreference extends EditTextPreference { ...

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

    // solving problem with insufficient space for showing EditText in EditTextPreference's dialog. This problem exists only
    // on HTC WildFire with android OS 2.2
    if ( Build.MODEL.equals("HTC Wildfire") && 8 == Integer.valueOf(android.os.Build.VERSION.SDK) )
    {
        _makeMoreRoomForEditText();
    }

}

private void _makeMoreRoomForEditText()
{
    EditText editText = getEditText();

    View parent1 = (View) editText.getParent();
    View parent2 = (View) parent1.getParent();
    View parent3 = (View) parent2.getParent();
    View parent4 = (View) parent3.getParent();
    View parent5 = (View) parent4.getParent();

    editText.setPadding(editText.getPaddingLeft(), 0, editText.getPaddingRight(), 0);
    parent1.setPadding(parent1.getPaddingLeft(), 0, parent1.getPaddingRight(), 0);
    parent3.setPadding(parent1.getPaddingLeft(), 0, parent1.getPaddingRight(), 0);
    parent5.setPadding(parent5.getPaddingLeft(), 0, parent5.getPaddingRight(), 0);

    ViewGroup par5 = (ViewGroup) parent5;
    View v = par5.getChildAt(0);

    v.setPadding(v.getPaddingLeft(), 3, v.getPaddingRight(), 3);// empirically determined values - looks fine only on HTC WildFire device with 2.2 Android
}

}

于 2012-01-26T19:44:34.607 に答える
1

2 つの提案: 1) キーボードが標準の Android のものよりも高いように見えるため、十分なスペースが得られる場合とそうでない場合がある簡単な方法: 設定アクティビティでアプリケーションのタイトル バーと Android のステータス バーを非表示にします。これにより、ダイアログボックスが少し上に移動します。

@Override
public void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    super.onCreate(savedInstanceState);

2) 難しい方法は、DialogPreference または EditTextPreference を拡張して独自のカスタム設定コントロールを作成し、そのコントロールに対して、タイトルを小さくするかタイトルを付けないか、または [OK/キャンセル] ボタンなどを小さくする独自のレイアウトを定義することです。次に、そのカスタムコントロールをpreferences.xmlに入れます

于 2011-05-22T10:13:17.707 に答える