2

こんにちは、タブホストとホロテーマがあります。クリックしたタブの下の青色を変更しようとしましたが、成功しませんでした。これは 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>

画像リンク

上のリンクの写真に似ています。私がしたいのは、タブ 1 の下の青色のストライプを変更することだけです。

私はこれを約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>

これは私が青い線のために変更しようとしたスタイルですが、成功しませんでした

スタイル.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>

線の色を変更したいだけです。助けていただければ幸いです。

4

1 に答える 1

1

TabHost があるため、ActionBar のタブを使用している場合よりもはるかに複雑です。私たちのアプリで解決した解決策は、フレームワークの 9 パッチ イメージをタブ インジケーター用にカスタマイズすることでした。カスタム タブ インジケーターを参照する方法がないように見えるため、タブ ビューも複製し、TabHost のタブを作成するときにそれを使用する必要がありました。これらのファイルの一部を取得するには、完全なフレームワーク ソースをダウンロードする必要があります。必要な作業は次のとおりです。

1) フレームワーク ソースからファイル /data/res/drawable/tab_indicator_holo.xml をコピーします。

2) tab_indicator_holo.xml で参照されている 9 つのパッチをコピーし、アプリケーションに合わせて変更します。含める密度ごとに、次のファイルが必要です。

  • tab_selected_pressed_holo.9.png
  • tab_unselected_pressed_holo.9.png
  • tab_selected_focused_holo.9.png
  • tab_unselected_focused_holo.9.png
  • tab_selected_holo.9.png
  • tab_unselected_holo.9.png

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));
    }
}

正確なホロの外観が必要でない場合は、これを少し単純化できます。お役に立てれば!

于 2012-12-23T21:22:56.477 に答える