問題描述
我已經閱讀了討論這個問題的其他問題,所有這些問題都適用于我的布局,除了對于第一個創建的布局.
I've read the other questions discussing this, and all of them work for my layouts, except for the very first one created.
目前,這是我的 onCreate
方法的頂部:
At the moment, this is at the top of my onCreate
method:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
^ 這樣至少鍵盤不會在啟動時彈出,但 EditText
仍然專注于.
^ That makes it so at least the keyboard doesn't pop up on startup, but the EditText
is still focused on.
這是我的 EditText
的 XML
:
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30" >
</EditText>
這就是我提出我的活動時的樣子:
This is what it looks like when I bring up my activity:
問題在于,對于某些手機,當 EditText
像這樣聚焦時,它們無法在其中寫入.我希望它不聚焦.
The problem is that with some phones, when an EditText
is focused like this, they can't write in it. I want it to not focus.
我所做的工作適用于提出的下一個布局,因為 EditTexts
沒有關注它,并且看起來更像這樣:
What I've done works for the next layouts brought up in that it the EditTexts
are not focused on and would look more like this:
但請注意,這是相同的布局.這是用戶被帶回該屏幕后的屏幕,這表明 XML
沒有問題,因為這是相同的 XML
,但問題是EditText
僅在創建 Activity 時關注.
Notice that it's the same layout, though. This is the screen after the user has been brought back to this screen, which would indicate nothing wrong with the XML
because this is the same XML
, but the problem is that the EditText
is only focused on when the activity is created.
我已經完成了研究,所有其他問題都沒有幫助我解決這個問題(但他們確實幫助鍵盤沒有出現,謝天謝地).我怎樣才能使啟動時的 EditText
看起來像第二個屏幕截圖,而不是第一個屏幕截圖?
I've done research and all of the other questions don't help me with this (they did however help the keyboard not show up, thankfully). How can I make it so the EditText
on startup will look like the second screenshot, rather than the first?
推薦答案
您可以設置 Layout 的屬性,如 android:descendantFocusability="beforeDescendants"
和 android:focusableInTouchMode="true"代碼>
You can set property of Layout like android:descendantFocusability="beforeDescendants"
and android:focusableInTouchMode="true"
示例:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true" >
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30" >
</EditText>
</RelativeLayout>
希望這篇文章有幫助;)
May this one helpful ;)
這篇關于創建Activity時如何使EditText不聚焦的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!