2

Androidでタブのスタイルを設定しようとして問題が発生しました。

オープンソースのAndroidの連絡先リストにあるものとまったく同じように見せたいです(https://android.googlesource.com/platform/packages/apps/Contactsを参照 )。

問題は、画面に表示すると、連絡先アプリとは少し異なって見えることです。

私のタブ

次のようになります。

ここに画像の説明を入力してください

背景色が少し異なり、テキストの色が異なることに注意してください。

基本的に同じコードとアイコンであるため、なぜこれが当てはまるのかわかりません。

私のタブレイアウトコードは次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="0dp">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="0dp" />
    </LinearLayout>
</TabHost>

そこには特別なものは何も含まれていません。TabActivityは次のとおりです。

public class TabbedActivity extends TabActivity implements
        TabHost.OnTabChangeListener {

    private TabHost tabHost;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        final Intent intent = getIntent();

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.tab);

        tabHost = getTabHost();
        tabHost.setOnTabChangedListener(this);

        setupLatestTab();
        setupSavedTab();

        tabHost.setCurrentTab(0);
    }

    private void setupLatestTab() {

        Intent intent = new Intent().setClass(this, ResultsActivity.class);

        tabHost.addTab(tabHost
                .newTabSpec("latest")
                .setIndicator("Latest",
                        getResources().getDrawable(R.drawable.ic_tab_recent))
                .setContent(intent));
    }

    private void setupSavedTab() {

        Intent intent = new Intent().setClass(this, ResultsActivity.class);

        tabHost.addTab(tabHost
                .newTabSpec("saved")
                .setIndicator("Saved",
                        getResources().getDrawable(R.drawable.ic_tab_starred))
                .setContent(intent));
    }

    @Override
    public void onTabChanged(String tabId) {
        // Because we're using Activities as our tab children, we trigger
        // onWindowFocusChanged() to let them know when they're active. This may
        // seem to duplicate the purpose of onResume(), but it's needed because
        // onResume() can't reliably check if a keyguard is active.
        Activity activity = getLocalActivityManager().getActivity(tabId);
        if (activity != null) {
            activity.onWindowFocusChanged(true);
        }
    }

}

ドローアブルフォルダの同じ画像も使用しています。

タブアクティビティでこのようなことを行うことで、タブの背景を手動で設定できることを知っています

tabHost.getTabWidget().getChildAt(index).setBackgroundColor(Color.parseColor("#ff202020"));

しかし、連絡先アプリはこの種のことをどこでも行っていないので(トップタブコードのほとんどはDialtactsActivityにあります)、タブを表示するときにオープンソースアプリが行っていることを実行したいだけです-方法と理由がわかりません基本的に同じコードとリソースを使用している場合、連絡先アプリケーションのタブははるかに見栄えが良くなります。

些細なことを見逃しているだけだと思いますか?

4

1 に答える 1

2

これは、Androidの最小バージョンが指定されていないという問題であることが判明しました。

追加した:

<uses-sdk android:minSdkVersion="8" />

androidmanifestに、それはうまくいきました。以前のバージョンのAndroidでは古いタブのルックアンドフィールに戻っていたと思います。

于 2011-06-02T14:46:32.100 に答える