为什么Android TabHost会从TextView中窃取焦点?

为什么Android TabHost会从TextView中窃取焦点?,第1张

概述我有一个使用以下布局的应用程序: alt text http://img15.imageshack.us/img15/238/screenshot003xbo.png 当应用程序启动时,焦点位于第一个TextView上,但如果您尝试在其中键入任何字母,焦点将直接转到选项卡.似乎我不是唯一一个fighting with this issue,也许这与以下内容有关: http://groups.goo 我有一个使用以下布局的应用程序:

alt text http://img15.imageshack.us/img15/238/screenshot003xbo.png

当应用程序启动时,焦点位于第一个TextVIEw上,但如果您尝试在其中键入任何字母,焦点将直接转到选项卡.似乎我不是唯一一个fighting with this issue,也许这与以下内容有关:

http://groups.google.com/group/android-developers/browse_thread/thread/435791bbd6c550a/8022183887f38f4f?lnk=gst&q=tabs+focus#8022183887f38f4f

无论如何,你知道为什么会这样吗?当然,任何解决方法都将受到赞赏.

我发布下面的代码,以避免重载问题:

XML:

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:orIEntation="vertical" androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent">    <linearLayout           androID:padding="5px"          androID:orIEntation="vertical"           androID:ID="@+ID/task_edit_panel"          androID:layout_wIDth="fill_parent"          androID:layout_height="fill_parent"           androID:layout_weight="50" >        <linearLayout androID:orIEntation="vertical"            androID:layout_wIDth="fill_parent"            androID:layout_height="wrap_content">            <TextVIEw androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content"                 androID:text="@string/Title"                 androID:textStyle="bold" />            <EditText androID:ID="@+ID/Title"               androID:layout_wIDth="fill_parent"                androID:layout_height="fill_parent" />        </linearLayout>        <TabHost androID:ID="@+ID/edit_item_tab_host"                androID:layout_wIDth="fill_parent"                androID:layout_height="fill_parent">             <TabWidget androID:layout_wIDth="fill_parent"                        androID:layout_height="wrap_content"                         androID:ID="@androID:ID/tabs" />             <FrameLayout              androID:ID="@androID:ID/tabcontent"              androID:layout_wIDth="fill_parent"              androID:layout_height="fill_parent"              androID:paddingtop="65px"> <!--  you need that if you don't want the tab content to overflow -->               <linearLayout                   androID:ID="@+ID/edit_item_date_tab"                   androID:orIEntation="vertical"                    androID:layout_wIDth="fill_parent"                    androID:layout_height="fill_parent"                    androID:padding="5px" >                     <TextVIEw androID:layout_wIDth="wrap_content"                            androID:layout_height="wrap_content"                             androID:text="date"                              androID:textStyle="bold" />                </linearLayout>                <linearLayout                   androID:ID="@+ID/edit_item_geocontext_tab"                   androID:orIEntation="vertical"                    androID:layout_wIDth="fill_parent"                    androID:layout_height="fill_parent"                    androID:padding="5px" >                 <TextVIEw androID:layout_wIDth="wrap_content"                            androID:layout_height="wrap_content"                             androID:text="lIEu"                              androID:textStyle="bold" />                </linearLayout>                <linearLayout                   androID:ID="@+ID/edit_item_text_tab"                   androID:orIEntation="vertical"                    androID:layout_wIDth="fill_parent"                    androID:layout_height="fill_parent"                     androID:padding="5px">                 <EditText androID:ID="@+ID/details"                         androID:layout_wIDth="fill_parent"                        androID:layout_height="fill_parent"                        androID:scrollbars="vertical" />                </linearLayout>            </FrameLayout>        </TabHost>    </linearLayout>    <!-- Bottom pannel with "add item" button -->    <linearLayout           androID:padding="5px"          androID:orIEntation="horizontal"           androID:layout_weight="1"          androID:ID="@+ID/task_edit_panel"          androID:layout_wIDth="fill_parent"          androID:layout_height="wrap_content"          androID:background="#E7E7E7" >          <!--  Let the height set to fill_parent until we find a better way for the layout  -->          <button androID:ID="@+ID/item_edit_ok_button"                androID:layout_wIDth="fill_parent"                androID:layout_height="wrap_content"                androID:layout_gravity="bottom"                androID:text="@string/ok"                                androID:layout_weight="1" />           <button androID:ID="@+ID/item_edit_cancel_button"                androID:layout_wIDth="fill_parent"                androID:layout_height="wrap_content"                androID:layout_gravity="bottom"                androID:text="@string/cancel"                                androID:layout_weight="1" />    </linearLayout></linearLayout>

和Java代码:

TabHost tab_host = (TabHost) findVIEwByID(R.ID.edit_item_tab_host);     // don't forget this setup before adding tabs from a tabhost using a xml vIEw or you'll get an nullpointer exception    tab_host.setup();     TabSpec ts1 = tab_host.newTabSpec("TAB_DATE");    ts1.setIndicator(getString(R.string.when),getResources().getDrawable(R.drawable.ic_dialog_time));    ts1.setContent(R.ID.edit_item_date_tab);    tab_host.addTab(ts1);    TabSpec ts2 = tab_host.newTabSpec("TAB_GEO");    ts2.setIndicator(getString(R.string.where),getResources().getDrawable(R.drawable.ic_dialog_map));    ts2.setContent(R.ID.edit_item_geocontext_tab);    tab_host.addTab(ts2);    TabSpec ts3 = tab_host.newTabSpec("TAB_TEXT");    ts3.setIndicator(getString(R.string.what),getResources().getDrawable(R.drawable.ic_menu_edit));    ts3.setContent(R.ID.edit_item_text_tab);    tab_host.addTab(ts3);    tab_host.setCurrentTab(0);
解决方法 好吧,肯定是一个错误: http://code.google.com/p/android/issues/detail?id=2516.

希望它将在下一个版本中修复,因为对于具有高级布局的复杂应用程序来说,这是一个非常烦人的问题.

总结

以上是内存溢出为你收集整理的为什么Android TabHost会从TextView中窃取焦点?全部内容,希望文章能够帮你解决为什么Android TabHost会从TextView中窃取焦点?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1134050.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存