使用自定义FragmentTabHost 时 程序启动失败
来源:互联网 发布:js格式化日期时间 编辑:程序博客网 时间:2024/04/28 10:16
问题背景:
我的项目中使用Android自带的FragmentTabHost + Fragment 实现了底部操作栏切换的功能,但是在界面切换的时候发现不能保存fragment的状态,通过在网上查找资料发现可以使用自定义 FragmentTabHost 来保存Fragment 的状态。但是在实际使用中发现 添加FragmentTabHost 代码后,程序不能启动了。
解决方法:
通过调试代码发现,在对FragmentTabHost 对象加载时,出现加载失败
private FragmentTabHost mTabHost;mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
然后就想到修改了代码中的FragmentTabHost 对象,但是未修改xml资源中的 FragmentTabHost 对象
修改前:
<android.support.v4.app.FragmentTabHost android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/main_tab_item_bg"> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="0" /> </android.support.v4.app.FragmentTabHost>
修改后:
<com.example.fragmenttabhostdemo.FragmentTabHost android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/main_tab_item_bg"> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="0" /> </com.example.fragmenttabhostdemo.FragmentTabHost>
只要将资源中的FragmentTabHost 改为自己的文件路径程序即可正常运行了。
备注:
FragmentTabHost 修改的代码网上一搜都会出来,就不在这里贴出了。
阅读全文
1 0
- 使用自定义FragmentTabHost 时 程序启动失败
- FragmentTabHost 自定义
- 【FragmentTabHost】FragmentTabHost的使用
- FragmentTabHost 使用;
- FragmentTabHost使用
- FragmentTabHost使用
- 自定义的FragmentTabHost
- 使用FragmentTabHost时,tabwidget被frament覆盖。
- 程序启动失败排查步骤
- strace 解决程序启动失败
- JVM 本地连接失败时,检查运行程序JVM启动参数
- 使用VC开发ActiveX时,提示程序无法启动 要注册利用“regsvr32”命令控件的注册,注册失败方法
- FragmentTabHost的使用
- FragmentTabHost的使用
- fragmentTabHost的使用
- 使用FragmentTabhost代替Tabhost
- Android FragmentTabHost使用
- FragmentTabHost的使用
- C# revit 二次开发 创建线样式LineStyle
- 30分钟掌握ES6/ES2015核心内容(上)
- 元素的两种分类方式
- AsyncTask原理
- id Software_Mark
- 使用自定义FragmentTabHost 时 程序启动失败
- 如何制作一个vagrant的base box
- JavaScript中8个常见的陷阱
- CSK跟踪算法简介及代码的解读
- 开发注意事项-1
- Linux串口驱动程序(5)-串口接收分析
- Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [184,726] millisec
- POJ2887
- 内网与外网之间是如何通信的