[英]Styling the actionbar in android
i'am following the documentation on [developers.android][1] site to customize my action bar.我正在按照 [developers.android][1] 站点上的文档来自定义我的操作栏。
the problem is that the action bar doesn't accept the style i made.问题是操作栏不接受我制作的样式。 this is the file 14/style (i'am testing on 4.3 android version device):这是文件 14/style(我正在 4.3 android 版本设备上测试):
<resources>
<!-- the theme applied to the application or activity -->
<style name="AppTheme"
parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/actionbar_color</item>
<item name="android:icon">@drawable/ic_launcher</item>
</style>
</resources>
and this is a part of my manifest :这是我的清单的一部分:
<application
android:name="com.fakher.actualitefoot.controller.AppController"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
what must i do ?我必须做什么 ? note : i'm using the support library, the application support api-9 [1]: https://developer.android.com/training/basics/actionbar/styling.html#AndroidThemes注意:我正在使用支持库,应用程序支持 api-9 [1]: https : //developer.android.com/training/basics/actionbar/styling.html#AndroidThemes
I designed my Action Bar like the below: I created an custom_action_bar.xml我像下面这样设计了我的操作栏:我创建了一个custom_action_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#526e83"
android:descendantFocusability="blocksDescendants">
<ImageView
android:id="@+id/ContactImageId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logo"
android:paddingLeft="100dp"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="10dp">
<TextView
android:id="@+id/CTS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:textColor="#ffffff"
android:text="CTS"
android:textStyle="bold"/>
<TextView
android:id="@+id/UserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp"
android:textColor="#ffffff"
android:text="Welcome: HKH"/>
</LinearLayout>
</LinearLayout>
then in onCreate in my activity i called this method:然后在我的活动中的 onCreate 中,我调用了这个方法:
public void customActionBar() {
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
actionBar.setIcon(android.R.color.transparent);
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#526e83")));
View cView = getLayoutInflater().inflate(R.layout.custom_action_bar, null);
actionBar.setCustomView(cView);
}
I hope this may help you in finding what you want我希望这可以帮助你找到你想要的
If you want to style your actionBar there is another easy way to do it.如果您想为 actionBar 设置样式,还有另一种简单的方法可以做到。
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#8B58A3")));
LayoutInflater inflater = LayoutInflater.from(this);
@SuppressLint("InflateParams") View v = inflater.inflate(R.layout.titleview, null);
TextView frag1 = (TextView)v.findViewById(R.id.titleFragment1);
frag1.setTypeface(yourdesiredFont);
actionBar.setCustomView(v);
and in your textview add whatever style or items you want to add to the actionBar and it will work great.并在您的 textview 中添加您想要添加到 actionBar 的任何样式或项目,它会很好用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.