1

2 つのタブにこれらのコードがあります。色を変えたいのですがやり方がわかりません。Java ファイルまたは xml で行う必要がありますか? ありがとうございました

これが私のコードです

import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.TabHost;

// This is now the first activity that you see when you enter the app, it derives from      TabActivity
public class TabsActivity extends TabActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);



    // The activity displays a TabHost layout with a TabWidget below the actual  tab contents
    setContentView(R.layout.tabs);

    // Two tabs are added one displays the main list activity, the other an     info activity
    addNewTab("Kalender", MainActivity.class);
    addNewTab("Info", InfoActivity.class);
}


// This function defines and adds a tab to the interface
private void addNewTab(String name, Class<? extends Activity> activityClass)
{
    TabHost tabHost = getTabHost();

    // The new tab will display a separate activity, so it needs an intent for it
    Intent activityIntent = new Intent().setClass(this, activityClass);

    // The TabSpec sets the internal name and the visible name of the newly created    tab
    TabHost.TabSpec spec =     tabHost.newTabSpec(name).setIndicator(name).setContent(activityIntent);

    // Finally, the new tab is added to the TabHost
    tabHost.addTab(spec);
}
}
4

4 に答える 4

2

TABの文字色と背景色を変更する

    for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
    {

        tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.WHITE); //Changing background color of tab

        TextView tv = (TextView) tabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); /*for Selected Tab changing text color*/
        tv.setTextColor(Color.BLACK);
    }
于 2012-06-18T06:00:48.507 に答える
0

タブの外観をカスタマイズする場合は、独自のタブ ウィジェットを使用する必要があります。問題は、ほとんどの Android ウィジェットがビットマップを使用してテーマ化されているため、グラデーション カラーを単純に変更することはできません。

標準ウィジェットの backgroundColor を単純に変更することを提案する人もいますが、かなりフラットに見えます。

独自のウィジェットを使用すると、次のようになります。

// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("artists").setIndicator("Artists",
                  res.getDrawable(R.drawable.ic_tab_artists))
              .setContent(intent);
tabHost.addTab(spec);

また、Android スタイル ガイドのタブ セクションもご覧ください

于 2012-06-16T21:00:16.880 に答える
0

これは、単一のタブの背景に色を持たせ、色を設定する 1 つの方法です。

tabHost.getTabWidget().getChildAt(tabIndex).setBackgroundColor(color);
于 2012-06-16T21:04:06.777 に答える