《求救》Android-使用tabhost时选项卡顶部出现空白<如图>在线等。

fl_stony 2013-08-08 09:43:30

部分代码如下
Activity中代码:

protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
super.setContentView(R.layout.main_tabs);
this.myTabHost = this.getTabHost();
Intent intent = this.getIntent();
Bundle bundle = intent.getExtras();
String title = bundle.getString("courseName");
TextView tvTitle = (TextView)findViewById(R.id.title_tab);
tvTitle.setText(title);
//this.myTabHost = (TabHost) super.findViewById(R.id.tabhost);
//this.myTabHost.setup(); //建立TabHost对象
intent = new Intent(TabClassActivity.this,CourseInfoActivity.class);
intent.putExtras(bundle);
TabSpec myTab1 = this.myTabHost.newTabSpec("courseInfo")
.setIndicator(getResources().getString(this.strRes[0]))
.setContent(intent);
myTabHost.addTab(myTab1);
intent = new Intent(TabClassActivity.this,RelativeCoursesActivity.class);
intent.putExtras(bundle);
TabSpec myTab2 = this.myTabHost.newTabSpec("relativeCourses")
.setIndicator(getResources().getString(this.strRes[1]))
.setContent(intent);
myTabHost.addTab(myTab2);
intent = new Intent(TabClassActivity.this,RelativeBooksActivity.class);
intent.putExtras(bundle);
TabSpec myTab3 = this.myTabHost.newTabSpec("relativeBooks")
.setIndicator(getResources().getString(this.strRes[2]))
.setContent(intent);
myTabHost.addTab(myTab3);
}

XML布局文件中代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
android:id="@+id/title_tab"
android:layout_width="match_parent"
android:layout_height="50sp"
android:background="@color/dark_gray"
android:textSize="25sp"
android:gravity="center"
android:textColor="@color/white"/>
<TabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
android:id="@android:id/tabcontent"
android:paddingBottom="60sp"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<RadioGroup
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical" >
<RadioButton
android:id="@+id/radio_bn0"
android:text="@string/courseInfo"/>
<RadioButton
android:id="@+id/radio_bn1"
android:text="@string/relativeCourses"/>
<RadioButton
android:id="@+id/radio_bn2"
android:text="@string/relativeBooks"/>
</RadioGroup>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>


</TabHost>
</LinearLayout>


开始好好的。好像是我在清单文件中设置了android:theme="@android:style/Theme.Light.NoTitleBar"就成这样了,为什么?
大神们求救啊。小弟初学Android。灰常感谢啦!
...全文
270 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
A562806113 2013-08-24
  • 打赏
  • 举报
回复
楼主后来解决了吗?我遇到一样的问题,不知道问题在哪里。
fl_stony 2013-08-10
  • 打赏
  • 举报
回复
引用 6 楼 Jia_H 的回复:
相对布局的高度如何设定的,还有就是背景是如何设定的,这些会影响到你显示的结果。
我tabhost三个子页都是这样的。子页的布局应该没有问题吧?
Jia_H 2013-08-10
  • 打赏
  • 举报
回复
相对布局的高度如何设定的,还有就是背景是如何设定的,这些会影响到你显示的结果。
fl_stony 2013-08-10
  • 打赏
  • 举报
回复
引用 3 楼 a357664853 的回复:
我也遇到过,你的首页中间那些课程号是用什么布局器的
上面那个课程名是一个textView。中间的课程信息是用的相对布局。
fl_stony 2013-08-10
  • 打赏
  • 举报
回复
引用 2 楼 Jia_H 的回复:
你是说没有上面的Title了吧,你设定的Theme就是没有Title的风格呀。难道不知道什么意思就设定上去用吗? 你可以找找有关android style的介绍。
谢谢。我是要设置成Notitle的风格,开始没设置notitle的时候选项卡上方没出现空白。设置了以后就出现了。你看图片 我是说选项卡上的字在选项卡的下方。
Roth- 2013-08-10
  • 打赏
  • 举报
回复
我也遇到过,你的首页中间那些课程号是用什么布局器的
Jia_H 2013-08-09
  • 打赏
  • 举报
回复
你是说没有上面的Title了吧,你设定的Theme就是没有Title的风格呀。难道不知道什么意思就设定上去用吗? 你可以找找有关android style的介绍。
fl_stony 2013-08-09
  • 打赏
  • 举报
回复
大神们呢 快来帮帮我啊

80,337

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧