以下 TabHost
, NoFocusStealTabHost
,实施 OnAttachStateChangeListener
界面来实施标签-focus-steal解决方法:
TabHost tabs steal focus when using Hardware Keyboard
此 TabHost
还会实施 OnTabChangeListener
界面来监听标签更改事件,并调用 RequestFocus
< / strong>()发现第一个可聚焦的视图。
RemoveOnTouchModeChangeListener
()会阻止 RequestFocus
()工作吗? RequestFocus
()或 RequestFocusFromTouch
()不会让孩子专注于 EditText
。必须明确触摸它才能使(蓝牙)键盘输入进入它(这似乎不方便用户使用)。
布局
<Views.NoFocusStealTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
...
</Views.NoFocusStealTabHost>
段
LocalActivityManager lam = new LocalActivityManager(Activity, false);
_tabHost = (NoFocusStealTabHost)_thisView.FindViewById(Android.Resource.Id.TabHost);
lam.DispatchCreate(_bundle);
_tabHost.Setup(lam);
自定义TabHost
public class NoFocusStealTabHost : TabHost,
View.IOnAttachStateChangeListener,
TabHost.IOnTabChangeListener
{
public NoFocusStealTabHost(Context context, IAttributeSet attributes) : base(context, attributes)
{
// Prevent TabHost from stealing focus (legacy android bug)
AddOnAttachStateChangeListener(this);
SetOnTabChangedListener(this);
}
void View.IOnAttachStateChangeListener.OnViewDetachedFromWindow(View view) { }
void View.IOnAttachStateChangeListener.OnViewAttachedToWindow(View view)
{
// Prevent TabHost from stealing focus (legacy android bug)
ViewTreeObserver.RemoveOnTouchModeChangeListener(this);
}
void IOnTabChangeListener.OnTabChanged(string tabId)
{
IList<View> vFocusables = CurrentView.GetFocusables(FocusSearchDirection.Down);
if (vFocusables != null && vFocusables.Count > 0)
{
//vFocusables[0].RequestFocus();
vFocusables[0].RequestFocusFromTouch();
}
}
}