Android 导航到下一个活动时更改操作栏颜色及其文本对齐方式
我想在我的Android应用程序中更改ActionBar的颜色 如果我点击按钮转到下一个活动,我也想更改Actionbar的颜色,但它显示“不幸的是,应用程序已停止” 下面是我的代码,如果有什么错误请告诉我 我的代码: 舱单代码:Android 导航到下一个活动时更改操作栏颜色及其文本对齐方式,android,android-activity,android-actionbar,android-fragmentactivity,Android,Android Activity,Android Actionbar,Android Fragmentactivity,我想在我的Android应用程序中更改ActionBar的颜色 如果我点击按钮转到下一个活动,我也想更改Actionbar的颜色,但它显示“不幸的是,应用程序已停止” 下面是我的代码,如果有什么错误请告诉我 我的代码: 舱单代码: <application android:allowBackup="true" android:icon="@drawable/app_icon_152" android:label="@string/app_name" andr
<application
android:allowBackup="true"
android:icon="@drawable/app_icon_152"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@android:style/Theme.Light">
<activity
android:name=".WelcomeScreen"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SignIn"
android:label="Sign In"
android:theme="@style/MyTheme"
android:parentActivityName=".WelcomeScreen"></activity>
</application>
values/theme.xml代码:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">@style/TitleBarTextColor</item>
<item name="android:background">#3366CC</item>
<item name="android:icon">@drawable/backarrow_white</item>
</style>
<style name="TitleBarTextColor" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#ffffff</item>
</style>
</resources>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowActionBar">true</item>
</style>
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowBackground">@drawable/splashscreen</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">false</item>
</style>
</resources>
@样式/MyActionBar
@样式/标题栏颜色
#3366毫升
@可拉拔/反箭头\白色
#ffffff
values/styles.xml代码:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">@style/TitleBarTextColor</item>
<item name="android:background">#3366CC</item>
<item name="android:icon">@drawable/backarrow_white</item>
</style>
<style name="TitleBarTextColor" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#ffffff</item>
</style>
</resources>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowActionBar">true</item>
</style>
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowBackground">@drawable/splashscreen</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">false</item>
</style>
</resources>
@颜色/原色
@颜色/原色暗
@颜色/颜色重音
真的
真的
@空的
@可抽出式/飞溅式挡风玻璃
假的
假的
任何帮助都将不胜感激。提前感谢。最佳做法是使用工具栏: 使用工具栏,您可以设置要使用的布局,并更改背景颜色和文本对齐方式。试试这个
<resources>
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">ANY_HEX_COLOR_CODE</item>
</style>
@样式/MyActionBar
任何十六进制颜色代码
您没有显示java代码的起始位置,但请尝试此错误
ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#95CDBA")));
actionBar.setTitle(Html.fromHtml("<font color='#000099'>Hello World</font>"));
actionBar.setBackgroundDrawable(新的ColorDrawable(Color.parseColor(“#000000”));试试这个,你能复制一下你的日志吗?谢谢。我必须为后退按钮、中间文本和文本颜色设计自定义工具栏。对吗?您可以根据需要自定义布局(文本重力、颜色…)。使用getSupportActionBar()设置后退按钮。setDisplayHomeAsUpEnabled(true);getSupportActionBar().setDisplayShowHomeEnabled(true);