Android 在eclipse中设置选项卡背景
我正在制作一个android应用程序,我的xml中有一个tabhost和两个tab。我给他们打过电话,他们工作得很好。但我想去掉标签上难看的灰色/橙色。我尝试过使用图像设置背景。我使用了以下代码:Android 在eclipse中设置选项卡背景,android,eclipse,tabs,Android,Eclipse,Tabs,我正在制作一个android应用程序,我的xml中有一个tabhost和两个tab。我给他们打过电话,他们工作得很好。但我想去掉标签上难看的灰色/橙色。我尝试过使用图像设置背景。我使用了以下代码: th.getTabWidget().setBackgroundResource(R.drawable.tab_normal); 但它的表现是这样的: 我怎样才能让它取代灰色和橙色 谢谢您可以拥有tabwidget的背景: <TabHost android:id="@androi
th.getTabWidget().setBackgroundResource(R.drawable.tab_normal);
但它的表现是这样的:
我怎样才能让它取代灰色和橙色
谢谢您可以拥有tabwidget的背景:
<TabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/tabbackground"
android:layout_margin="7dp"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@android:id/tabs"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:background="@drawable/list_shape">
</FrameLayout>
</RelativeLayout>
您可以拥有tabwidget的背景:
<TabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/tabbackground"
android:layout_margin="7dp"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@android:id/tabs"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:background="@drawable/list_shape">
</FrameLayout>
</RelativeLayout>
完全自定义tabwidget的步骤:
<TabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/tabbackground"
android:layout_margin="7dp"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@android:id/tabs"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:background="@drawable/list_shape">
</FrameLayout>
</RelativeLayout>
图标
和一个文本视图
组成。你可以选择任何你想要的布局。请注意,父布局具有有状态背景tabwidget\u选择器
。此可绘制颜色是替换默认橙色焦点颜色的关键。您可以选择自己的焦点颜色
<?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="40dp"
android:background="@drawable/tabwidget_selector"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/tabIndicatorIcon"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginTop="2dp" />
<TextView
android:id="@+id/tabIndicatorText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:textColor="@color/white" />
完全自定义tabwidget的步骤:
<TabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/tabbackground"
android:layout_margin="7dp"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@android:id/tabs"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:background="@drawable/list_shape">
</FrameLayout>
</RelativeLayout>
图标
和一个文本视图
组成。你可以选择任何你想要的布局。请注意,父布局具有有状态背景tabwidget\u选择器
。此可绘制颜色是替换默认橙色焦点颜色的关键。您可以选择自己的焦点颜色
<?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="40dp"
android:background="@drawable/tabwidget_selector"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/tabIndicatorIcon"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginTop="2dp" />
<TextView
android:id="@+id/tabIndicatorText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:textColor="@color/white" />
你可以请客了。我不能让你为即将进入的地狱做好准备,这就是android上标签的可怕之处。对于每个制造商和每个版本的android,样式都是不同的。这也是为什么现在不推荐使用旧选项卡的原因。。。你应该通过使用actionbarsherlock或类似的工具开始使用新的工具。哦,我还忘了有些功能不能在android的某个版本上设计,除非你做一些可能会破坏的危险代码:SOk,Thank:P我还在我的应用程序中使用ABS(action bar sherlock)。但是我希望标签只能从中间和下面开始。而不是完整的布局。再次感谢。你说的“只从中间到下面”是什么意思?在标签上有一个图像,这样你就可以享受图像标签1 |标签2了。我不能让你为即将进入的地狱做好准备,这就是android上标签的可怕之处。对于每个制造商和每个版本的android,样式都是不同的。这也是为什么现在不推荐使用旧选项卡的原因。。。你应该通过使用actionbarsherlock或类似的工具开始使用新的工具。哦,我还忘了有些功能不能在android的某个版本上设计,除非你做一些可能会破坏的危险代码:SOk,Thank:P我还在我的应用程序中使用ABS(action bar sherlock)。但是我希望标签只能从中间和下面开始。而不是完整的布局。再次感谢。你说的“只从中间到下面”是什么意思?在标签上有一个图像,因此它将是图像标签1 | tab2tanks,这对我很有帮助。谢谢,这对我很有帮助。