And*_*sWT 5 c# xamarin.android android-actionbar xamarin
如何在Xamarin android中以编程方式更改操作栏标题颜色?我在互联网上尝试了很多事情,但我只是找不到方法。
我不想切换到工具栏,因为我不知道它的代码,我也不知道是否有可能使工具栏看起来与下面代码中的动作栏完全相同。
这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Support.V7.App;
using Android.Graphics.Drawables;
using Android.Graphics;
namespace actionbarTitleColor
{
[Activity(Label = "myActivity")]
public class myActivity : Activity
{
protected override void OnCreate(Bundle bundle) {
base.OnCreate(bundle);
SetContentView(Resource.Layout.Rapsolie);
ActionBar.SetHomeButtonEnabled(true);
ActionBar.SetDisplayHomeAsUpEnabled(true);
ColorDrawable colorDrawable = new ColorDrawable(Color.ParseColor("#00b8ff"));
ActionBar.SetBackgroundDrawable(colorDrawable);
}
public override bool OnOptionsItemSelected(IMenuItem item) {
switch (item.ItemId) {
case Android.Resource.Id.Home:
Finish();
return true;
default:
return base.OnOptionsItemSelected(item);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
最简单的方法是自定义样式ActionBar,例如:
<resources>
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
</style>
<style name="MyTheme.ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#f08080</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
然后像这样在您的页面中应用此样式:
[Activity(Label = "YOURPACKAGENAME", MainLauncher = true, Icon = "@drawable/icon", Theme = "@style/MyTheme")]
Run Code Online (Sandbox Code Playgroud)
关于自定义样式的讨论很多ActionBar,您可以搜索它们。
我不想切换到工具栏,因为我不知道它的代码,我也不知道是否有可能使工具栏看起来与下面代码中的动作栏完全相同。
我个人认为Toolbar自定义布局使用起来比较容易,但是自android 5.0起就可以使用,有关如何编写代码的部分Toolbar,您可以参考Toolbar。
| 归档时间: |
|
| 查看次数: |
4685 次 |
| 最近记录: |