gpt4 book ai didi

android - 如何更改蓝色全息颜色?

转载 作者:太空狗 更新时间:2023-10-29 13:29:41 26 4
gpt4 key购买 nike

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

经过一些研究,我尝试使用网站 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

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

最佳答案

您收到的错误是因为您的项目或引用项目(如 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 layout 属性仅在 android Honeycomb 或更高版本中可用,因此我们需要以编程方式设置。

holo generator site在实现他们的 Artifact 时不是很有用,但非常方便的资源。完整实现见下文。

对于完整的实现:

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

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

注意:这些选项卡在 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>

关于android - 如何更改蓝色全息颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17134703/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com