gpt4 book ai didi

android - 无法正确设置 Android Actionbar 背景

转载 作者:搜寻专家 更新时间:2023-11-01 08:51:05 25 4
gpt4 key购买 nike

问题当我设置 ActionBar 背景颜色时,Bar 看起来像这样:

我不能在这里上传图片所以这是文件: Android ActionBar Problem

我的值(value)观/风格文件

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.

-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.

-->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="actionBarStyle">@style/ActionBarTheme</item>
</style>

<!-- Action Bar theme -->
<style name="ActionBarTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:background">@drawable/actionbar</item>
<item name="background">@drawable/actionbar</item>
</style>

<style name="FullscreenTheme" parent="android:style/Theme.NoTitleBar.Fullscreen">
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowBackground">@null</item>
<item name="metaButtonBarStyle">@style/ButtonBar</item>
<item name="metaButtonBarButtonStyle">@style/ButtonBarButton</item>
</style>

<style name="ButtonBar">
<item name="android:paddingLeft">2dp</item>
<item name="android:paddingTop">5dp</item>
<item name="android:paddingRight">2dp</item>
<item name="android:paddingBottom">0dp</item>
<item name="android:background">@android:drawable/bottom_bar</item>
</style>

<style name="ButtonBarButton" />

</resources>

我的 list 文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.application"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />

<application
android:allowBackup="true"
android:icon="@drawable/symbol"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.application.Main"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.application.Settings"
android:parentActivityName="com.application.Main"
android:screenOrientation="portrait"
android:theme="@style/ActionBarTheme">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.application.Main" />
</activity>
<activity
android:name="com.application.DateList"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait"
android:theme="@style/FullscreenTheme" >
</activity>
</application>

</manifest>

我也试过这个,但同样的事情发生了

ColorDrawable draw = new ColorDrawable(R.color.grey);
getSupportActionBar().setBackgroundDrawable(draw);

我的颜色可绘制

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

<solid
android:color="@color/grey" />

</shape>

最佳答案

getSupportActionBar().setBackgroundDrawable(draw);

在你的情况下应该是

getSupportActionBar().setBackgroundDrawable(getResources.getDrawable(R.drawable.your_drawable_name);

ColorDrawable 的构造函数采用表示颜色的 int,而不是颜色的 id。立即使用

ColorDrawable draw = new ColorDrawable(getResources().getColor(R.color.grey));

编辑:

关于style.xml,有android前缀的item和没有android前缀的item都需要:

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">@style/ActionBarTheme</item>
<item name="actionBarStyle">@style/ActionBarTheme</item>
</style>

Lint 可能会提示它,因为 minSDK 值。如果是这样,您可以将 tools:ignore="NewApi" 添加到带有 android: 前缀的项目中。例如:

 <item name="android:actionBarStyle" tools:ignore="NewApi">@style/ActionBarTheme</item>  

关于android - 无法正确设置 Android Actionbar 背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23358751/

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