你好我有一个tabhost和一个holo主题,我试图改变你点击的标签下的蓝色 没有任何成功。 这是main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false"
android:orientation="vertical"
android:scrollbarAlwaysDrawVerticalTrack="false" >
<LinearLayout
android:id="@+id/tabhost_parent"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabHost
android:id="@+id/main_tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:id="@+id/tabhost_lierlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/regi_input02_tap"
android:showDividers="middle">
</TabWidget>
<LinearLayout
android:id="@+id/header_layout"
android:layout_width="match_parent"
android:layout_height="32dp"
android:orientation="horizontal"
android:background="@android:color/background_dark">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test Text"
android:textSize="23dp"
android:textColor="@android:color/background_light"
/>
</LinearLayout>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp">
<LinearLayout
android:id="@+id/sports_tab"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
<LinearLayout
android:id="@+id/busines_tab"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="busines"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/news_tab"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="news"
/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
</LinearLayout>
它看起来类似于上面链接中的图片,我想要做的就是更改tab1下的蓝色条纹。
我现在被搜索了大约2天,没有找到关于如何做到这一点的任何好的解释。
我试着玩资源 像这样:
这是manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.brodgate.mivzaki"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="14" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/CustomTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
这是我试图改变蓝线而没有任何成功的风格
styles.xml
<style name="CustomTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">@style/ActionBar</item>
</style>
<style name="ActionBar" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">@color/action_bar_background</item>
<item name="android:showDividers">beginning</item>
<item name="android:divider">@color/action_bar_divider</item>
</style>
我想要的只是改变线条颜色, 将不胜感激。
答案 0 :(得分:1)
由于你有一个TabHost,它比你使用ActionBar的标签要复杂得多。我们为我们的应用程序确定的解决方案是为选项卡指示器自定义框架9补丁图像。由于似乎没有办法引用自定义选项卡指示器,我们也必须复制选项卡视图,并在我们为TabHost创建选项卡时使用它。您必须下载完整的框架源以获取其中的一些文件。这是你需要做的:
1)从框架源复制文件/data/res/drawable/tab_indicator_holo.xml。
2)复制tab_indicator_holo.xml中引用的9个补丁并修改它们以适合您的应用程序。对于要包含的每个密度,您需要以下文件:
3)创建自定义标签样式:
<style name="MyCustomTabView" parent="@android:style/Widget.Holo.Tab">
<item name="android:background">@drawable/tab_indicator_holo</item>
</style>
4)从框架中创建选项卡视图布局的副本:
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="?android:attr/actionBarSize"
android:orientation="horizontal"
style="@style/MyCustomTabView">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingTop="12dip"
android:paddingBottom="12dip"
android:paddingLeft="12dip"
android:paddingRight="12dip"
android:visibility="gone"/>
<TextView
style="@android:style/Widget.Holo.ActionBar.TabText"
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:visibility="gone"/>
</LinearLayout>
5)最后一步是在您的活动代码中,当您创建选项卡时,将指示器设置为您从上面的布局创建的视图。这就是它的样子(这是来自ApiDemos示例应用程序的Tabs1.java,用于创建自定义指标视图):
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.apis.view;
import android.app.TabActivity;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.view.LayoutInflater;
import com.example.android.apis.R;
/**
* An example of tabs that uses labels ({@link TabSpec#setIndicator(CharSequence)})
* for its indicators and views by id from a layout file ({@link TabSpec#setContent(int)}).
*/
public class Tabs1 extends TabActivity {
private View createTabIndicator(Drawable icon, String title) {
if (mInflater == null) {
mInflater = getLayoutInflater();
}
View view = mInflater.inflate(R.layout.tab_view, null);
if (icon != null) {
ImageView imageView = (ImageView) view.findViewById(R.id.icon);
imageView.setImageDrawable(icon);
imageView.setVisibility(View.VISIBLE);
}
if (title != null) {
TextView textView = (TextView) view.findViewById(R.id.title);
textView.setText(title);
textView.setVisibility(View.VISIBLE);
}
return view;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TabHost tabHost = getTabHost();
LayoutInflater.from(this).inflate(R.layout.tabs1, tabHost.getTabContentView(), true);
tabHost.addTab(tabHost.newTabSpec("tab1")
.setIndicator(createTabIndicator(null, "tab1"))
.setContent(R.id.view1));
tabHost.addTab(tabHost.newTabSpec("tab2")
.setIndicator(createTabIndicator(null, "tab2"))
.setContent(R.id.view2));
tabHost.addTab(tabHost.newTabSpec("tab3")
.setIndicator(createTabIndicator(null, "tab3"))
.setContent(R.id.view3));
}
}
如果您不需要精确的Holo外观,可以稍微简化一下。希望这可以帮助!