我有 2 个片段,上面有几个 EditText 框。它们的布局相似,但是非常奇怪的是 1 将在 EditText 字段之间进行制表符,而另一个则不会。
这是我遇到的问题:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/loginparent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff008DFF" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dip"
android:background="#ff008DFF"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="40dip"
android:contentDescription="@string/logoDesc"
android:src="@drawable/logo1" />
<EditText
android:id="@+id/usernameLog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="@string/username"
android:imeOptions="actionNext"
android:singleLine="true"
android:textSize="14sp" />
<EditText
android:id="@+id/passwordLog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/password"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:singleLine="true"
android:textSize="14sp" />
<Button
android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/login" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="@string/newuser"
android:textColor="#ffffffff"
android:textSize="14sp" />
<Button
android:id="@+id/viewSignupBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/signup" />
</LinearLayout>
</LinearLayout>
<ProgressBar
android:id="@+id/progressBarLog"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:padding="70dip"
android:visibility="gone" />
</RelativeLayout>
当我从第一个 EditText 框中选择时,焦点消失然后在第二个选项卡上它将焦点移动到第二个字段。如果我标签焦点再次出现,然后再次标签,它会出现在它下面的按钮上。
除了获取指向 EditText 字段的指针之外,Fragment 的 onCreateView 没有什么特别之处。就像我说的,我有一个非常相似的第二个视图,效果很好。
当我标签时,我注意到我在 Logcat 中显示了这些警告:
04-24 19:31:29.695: D/InputEventConsistencyVerifier(2040): KeyEvent: ACTION_UP but key was not down.
04-24 19:31:29.695: D/InputEventConsistencyVerifier(2040): in android.support.v4.app.NoSaveStateFrameLayout@40f365b8
04-24 19:31:29.695: D/InputEventConsistencyVerifier(2040): 0: sent at 4325570000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_TAB, scanCode=15, metaState=0, flags=0x8, repeatCount=0, eventTime=4325570, downTime=4325514, deviceId=0, source=0x101 }
04-24 19:31:31.076: D/InputEventConsistencyVerifier(2040): KeyEvent: ACTION_UP but key was not down.
04-24 19:31:31.076: D/InputEventConsistencyVerifier(2040): in android.widget.EditText@40f78e98
04-24 19:31:31.076: D/InputEventConsistencyVerifier(2040): 0: sent at 4326945000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_TAB, scanCode=15, metaState=0, flags=0x8, repeatCount=0, eventTime=4326945, downTime=4326889, deviceId=0, source=0x101 }
04-24 19:31:32.255: D/InputEventConsistencyVerifier(2040): KeyEvent: ACTION_UP but key was not down.
04-24 19:31:32.255: D/InputEventConsistencyVerifier(2040): in android.widget.EditText@40f73678
04-24 19:31:32.255: D/InputEventConsistencyVerifier(2040): 0: sent at 4328123000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_TAB, scanCode=15, metaState=0, flags=0x8, repeatCount=0, eventTime=4328123, downTime=4328053, deviceId=0, source=0x101 }
编辑 - - - - - - - - -
好的,正如评论中所建议的,我向所有视图添加了 onFocusChanged 侦听器(循环遍历它们并添加了侦听器)并记录了视图是什么。每次我标签时,我都会得到日志,但奇怪的是,我标签到第一个 EditText 框并且日志说 editText 框有焦点,我再次标签并且焦点丢失但日志说同一个 EditText 框有焦点!再次选项卡,第二个获得焦点,日志显示正确的 id,选项卡再次失去焦点,但再次日志显示第二个 EditText 框有焦点,即使它没有!
非常奇怪的行为。