3

我想将默认蓝色更改为其他颜色...

经过一番研究,我尝试使用网站Android Holo Colors Generator。我从网站下载了文件并将它们添加到我的 android 应用程序中,但出现两个错误:

 - Attribute "divider" has already been defined attrs.xml, .../res/values, line 6   Android AAPT Problem
 - Error: No resource found that matches the given name (at 'drawable' with value '@color/transparent').    item_background_holo_light.xml, ../res/drawable, line 25    Android AAPT Problem

我试图评论这两行,但没有应用任何更改。有什么建议或帮助吗?

4

1 回答 1

2

您遇到的错误是因为您的项目或引用的项目(如 acionbarSherlock)具有已使用该名称的属性。您可以使用以下步骤解决此问题

1)随意注释掉该属性

2)定义您的自定义分隔线R.drawable.customDivider

<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <size android:width="1dip" />
    <solid android:color="#666666" />

</shape> 

3) 用于setDividerDrawable设置您的

mTabHost.getTabWidget().setDividerDrawable(getResources().getDrawable(R.drawable.customDivider));

注意:android:divider布局属性仅在 android Honeycomb 或更高版本中可用,因此我们需要以编程方式设置。

全息生成器站点在实现其工件时信息量不是很大,但资源非常方便。请参阅下面的完整实施。

对于完整的实施:

注意 另一种选择是使用Holo Everywhere 库来支持预蜂窝样式。

将下载的文件添加到项目中后,您将需要实现如下所示的内容。

注意:这些选项卡在Fragment中实现

有条件地应用下载的指标:

      public class TabsFrag extends Fragment {
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            FragmentTabHost retval = (FragmentTabHost)inflater.inflate(R.layout.home_tabbed_view, container, false);

            return retval;
        }
        public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
            FragmentTabHost mTabHost = (FragmentTabHost)getView().findViewById(android.R.id.tabhost);
            mTabHost.setup(getActivity(), getActivity().getSupportFragmentManager(), R.id.realtabcontent);

            //This is for stying to be the same across SDKs, we are supporting pre.
            if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB)
            {

mTabHost.getTabWidget().setDividerDrawable(getResources().getDrawable(R.drawable.customDivider));

                View tab1Indicator = getActivity().getLayoutInflater().inflate(R.layout.tab_indicator_holo, mTabHost.getTabWidget(), false);
                View tab2Indicator = getActivity().getLayoutInflater().inflate(R.layout.tab_indicator_holo, mTabHost.getTabWidget(), false);



                ((TextView) tab1Indicator.findViewById(android.R.id.title)).setText("Tab 1 label");
                mTabHost.addTab(mTabHost.newTabSpec("TAB1").setIndicator(tab1Indicator),
                        MenuHomeDashboard.class, null);

                ((TextView) tab2Indicator.findViewById(android.R.id.title)).setText("Tab 2 label");
                mTabHost.addTab(mTabHost.newTabSpec("TAB2").setIndicator(tab2Indicator),
                        MenuHomeNewsFeed.class, null);

            }
            else //No need to use the generated style unless you want to.
            {

                mTabHost.addTab(mTabHost.newTabSpec("TAB1").setIndicator("Tab 1 label"),
                        MenuHomeDashboard.class, null);
                mTabHost.addTab(mTabHost.newTabSpec("TAB2").setIndicator("Tab 2 label"),
                        MenuHomeNewsFeed.class, null);
            }
        }
        }

您的自定义选项卡布局:R.home_tabbed_view

<android.support.v4.app.FragmentTabHost
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TabWidget
            android:id="@android:id/tabs"

            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"/>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="0"/>

        <FrameLayout
            android:id="@+id/realtabcontent"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/>

    </LinearLayout>
</android.support.v4.app.FragmentTabHost>

以及您应该从全息颜色生成器收到的R.layout.tab_indicator_holo布局

<!-- 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="@dimen/tab_host_default_height"
    android:orientation="horizontal"
    style="@style/TabAppTheme"
    android:gravity="center">

    <ImageView
        android:id="@android:id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:visibility="gone"
        android:contentDescription="@null" />

    <TextView
        android:id="@android:id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        style="@style/TabTextAppTheme" />

</LinearLayout>
于 2013-09-13T15:36:27.550 回答