我正在构建一个选项卡式应用程序。TabHost 的效果非常好。不幸的是,我的团队负责人不喜欢标签的外观。他不喜欢小图标和标签之间的空隙。所以,我要么需要修改 TabHost,要么使用 ActivityGroup。
我的第一次尝试是更改 TabHost。
这是我的一个标签的drawable:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected, use grey -->
<item android:drawable="@drawable/ic_tab_timeline_grey"
android:state_selected="true" />
<!-- When not selected, use white-->
<item android:drawable="@drawable/ic_tab_timeline_white" />
<!-- This is a state-list drawable, which you will apply as the tab image. When the tab state changes, the tab icon will automatically switch between the images defined here. -->
</selector>
我在我的主要活动中初始化选项卡:
// Initialize a TabSpec for each tab and add it to the TabHost
intent = new Intent().setClass(this, TimelineActivity.class);
spec = tabHost.newTabSpec("timeline") .setIndicator("",
res.getDrawable(R.drawable.ic_tab_timeline))
.setContent(intent);
tabHost.addTab(spec);
(请注意,我将指标设置为空白。)
然后,我设置了背景图片:
TabWidget tw = getTabWidget();
//changeTabWidgetStyle(tw);
View tempView = tabHost.getTabWidget().getChildAt(0);
tempView.setBackgroundDrawable(getResources().getDrawable(R.drawable.timeline_on));
这成功地将背景设置为我想要的图像。但是,我的标签仍然有一个小图标,它覆盖了我的背景图像。我怎样才能摆脱图标?我在初始化选项卡时尝试将 Drawable 设置为 null,但这会导致我的应用程序崩溃。
即使我可以让它工作,看起来我仍然会有标签之间的空格。我怎样才能摆脱那些?
如果这不起作用,我可能不得不使用 ActivityGroup。不过,我宁愿不这样做,因为这似乎更复杂。
我正在使用这个例子:android: using ActivityGroup to embed Activity
LocalActivityManager mgr = getLocalActivityManager();
Intent i = new Intent(this, SomeActivity.class);
Window w = mgr.startActivity("unique_per_activity_string", i);
View wd = w != null ? w.getDecorView() : null;
if(wd != null) {
mSomeContainer.addView(wd);
}
我可以获得“选项卡”来更改和扩展布局,但我无法添加本地活动。我不确定要将视图添加到哪种“容器”。我的 xml 布局应该是什么样的?