我有一个从Android 1.5到4.0的应用程序。 Android 4.1导致一个简单的EditTextPreference问题。该应用程序始终处于横向模式。当我提出团队名称时,它看起来像这样。
Pic 1 http://myweb.midco.net/hgs/s1.jpg
然后当我点击编辑文本字段时,它总是看起来像这样。
Pic 1 http://myweb.midco.net/hgs/s2.jpg
但是在我的模拟器和三星Galaxy Tab 2与Android 4.1的投诉中,我得到了这个。
Pic 1 http://myweb.midco.net/hgs/s3.jpg
这会破坏文本字段。将清单更改为
android:windowSoftInputMode="stateVisible|adjustResize"
或
android:windowSoftInputMode="stateVisible|adjustPan"
没有帮助。将标题留空会取消标题,但您仍然无法看到编辑文本。以下是此Pref的代码。
EditTextPreference teamnamePref = new EditTextPreference(this);
teamnamePref.setTitle("Team Name");
teamnamePref.setKey( "t" + Team_ID );
teamnamePref.setSummary(TheTeamName);
teamnamePref.setDialogTitle("Enter Name For Team " + Team_ID);
teamnamePref.setDefaultValue(TheTeamName);
teamnamePref.getEditText().setSingleLine(true);
TeamCategory.addPreference(teamnamePref);
谢谢
答案 0 :(得分:1)
我创建了一种解决此bug的方法(在三星Galaxy S3,Acer A501和HTC Desire X上测试过):
// This method provides a work-around for a bug with EditTextPreference and the Samsung soft keyboard.
// When in landscape mode, the Samsung keyboard can obscure the text box, as it does not use fullscreen
// / extract mode like other keyboards do in this case. So we manually show an alert dialog with an
// EditText control, and update the preference value manually.
//
// Usage:
// Create a normal <Preference> in your XML file, then in your corresponding fragment, retrieve the
// preference object using its key and pass it to this method. E.g.
//
// EditTextPreferenceHelper.CreateEditTextPreferenceDialog(
// getActivity(),
// findPreference("yourPrefKey"));
public static void CreateEditTextPreferenceDialog(final Context context, Preference preference) {
preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(final Preference preference) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(preference.getTitle());
final EditText textBox = new EditText(context);
textBox.setImeOptions(EditorInfo.IME_ACTION_DONE);
textBox.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_SUBJECT);
textBox.setText(PreferenceManager.getDefaultSharedPreferences(context).getString(preference.getKey(), ""));
builder.setView(textBox);
builder.setPositiveButton("OK", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
PreferenceManager.getDefaultSharedPreferences(
context).edit().putString(preference.getKey(),
textBox.getText().toString()).commit();
dialog.dismiss();
}
});
builder.setNegativeButton("Cancel", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
return false;
}
});
}
答案 1 :(得分:0)
这样的事情应该可以胜任。您始终可以将软输入标志修改为其他内容,例如adjustPan。之前没有为您工作的原因是EditTextPreference会覆盖这些选项。
import android.content.Context;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.view.Window;
import android.view.WindowManager;
public class CustomEditTextPref extends EditTextPreference
{
public CustomEditTextPref(Context context)
{
super(context);
}
@Override
protected void showDialog(Bundle state)
{
super.showDialog(state);
Window window = getDialog().getWindow();
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}