我有一个简单的登录布局,包含两个EditText字段和一个要登录的按钮.问题是当软键盘打开时Actionbar消失,我将焦点从EditText更改为button,当我按下时Actionbar再次返回.当软键盘关闭并且我使用DPAD浏览EditTexts和button时,不会发生此问题.
我使用ActionbarSherlock,问题只出现在Android 2.x模拟器上,在4.x模拟器上一切正常.我知道ActionbarSherlock在可用的AndroID版本上使用本机Actionbar实现,因此它可能是ActionbarSherlock代码的问题.
我还执行了一个测试来检查Actionbar.isShowing()的值,但即使在屏幕上看不到Actionbar,它也会返回true.
我无法弄清楚在这种情况下发生了什么,有人有想法吗?
布局XML
<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:tools="http://schemas.androID.com/tools" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" tools:ignore="Uselessparent" > <linearLayout androID:layout_wIDth="250dp" androID:layout_height="wrap_content" androID:layout_centerInParent="true" androID:orIEntation="vertical" > <EditText androID:ID="@+ID/username" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:layout_marginBottom="10dp" androID:hint="@string/username" androID:inputType="textNoSuggestions" androID:nextFocusUp="@+ID/loginbutton" androID:imeOptions="actionNext" /> <EditText androID:ID="@+ID/password" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:layout_marginBottom="10dp" androID:hint="@string/password" androID:inputType="textPassword" androID:imeOptions="actionDone" /> <button androID:ID="@+ID/loginbutton" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_gravity="right" androID:text="@string/login" androID:textSize="20sp" androID:nextFocusDown="@+ID/username" /> </linearLayout></relativeLayout>
碎片代码
public class LoginFragment extends BaseFragment { @InjectVIEw(R.ID.loginbutton) protected button mLoginbutton; @InjectVIEw(R.ID.username) protected EditText mUsernameEditText; @InjectVIEw(R.ID.password) protected EditText mPasswordEditText; @OverrIDe public VIEw onCreateVIEw(LayoutInflater inflater, VIEwGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.login, container, false); } @OverrIDe public voID onStart() { super.onStart(); mLoginbutton.setEnabled(allFIEldsValID()); mLoginbutton.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { handleLogin(); } }); mPasswordEditText.setonEditorActionListener(new TextVIEw.OnEditorActionListener() { @OverrIDe public boolean onEditorAction(TextVIEw v, int actionID, KeyEvent event) { if (actionID == EditorInfo.IME_ACTION_DONE && allFIEldsValID()) { handleLogin(); } return false; } }); TextWatcher fIEldValIDatorTextWatcher = new TextWatcher() { @OverrIDe public voID afterTextChanged(Editable s) { } @OverrIDe public voID beforeTextChanged(CharSequence s, int start, int count, int after) { } @OverrIDe public voID onTextChanged(CharSequence s, int start, int before, int count) { mLoginbutton.setEnabled(allFIEldsValID()); } }; mUsernameEditText.addTextChangedListener(fIEldValIDatorTextWatcher); mPasswordEditText.addTextChangedListener(fIEldValIDatorTextWatcher); } private voID handleLogin() { getSherlockActivity().setSupportProgressbarIndeterminateVisibility(true); Intent intent = new Intent(getActivity(), LoginService.class); intent.putExtra(BaseIntentService.EXTRA_STATUS_RECEIVER, mResultReceiver); intent.putExtra(LoginService.ParaM_USERname, mUsernameEditText.getText().toString()); intent.putExtra(LoginService.ParaM_PASSWORD, mPasswordEditText.getText().toString()); getActivity().startService(intent); } private boolean allFIEldsValID() { return usernameFIEldisValID() && passwordFIEldisValID(); } private boolean usernameFIEldisValID() { return !TextUtils.isEmpty(mUsernameEditText.getText()); } private boolean passwordFIEldisValID() { return !TextUtils.isEmpty(mPasswordEditText.getText()); } @OverrIDe public voID onReceiveResult(int resultCode, Bundle resultData) { getSherlockActivity().setSupportProgressbarIndeterminateVisibility(false); super.onReceiveResult(resultCode, resultData); } @OverrIDe public voID onReceiveResultSuccess(Bundle resultData) { ((LoginActivity) getActivity()).redirectToSelectTeamwebActivity(resultData.getInt(LoginService.RESulT_USER_ID)); } @OverrIDe public voID onReceiveResultFailure(Bundle resultData) { mPasswordEditText.setText(""); String errorMessage = getString(R.string.invalID_login_credentials); Toast.makeText(getActivity(), errorMessage, Toast.LENGTH_LONG).show(); }}
解决方法:
ActionbarSherlock在内容视图内部的pre-ICS上附加兼容性 *** 作栏,而不是在Window的装饰视图中.因此,它可能会带来更多不便,可能会导致您所看到的意外行为.
如果您已将windowsoftinputMode设置为在IME打开时平移内容视图,则 *** 作栏将从屏幕上消失.解决这个问题的简单方法是使用不同的模式(例如,调整大小),该模式将重新布局内容视图并将 *** 作栏保持在屏幕上.
总结以上是内存溢出为你收集整理的android – 当焦点从EditText更改为Button时,ActionBarSherlock *** 作栏消失全部内容,希望文章能够帮你解决android – 当焦点从EditText更改为Button时,ActionBarSherlock *** 作栏消失所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)