我正在按照developers.android站点上的文档来自定义我的操作栏。
问题是动作条不接受我做的样式。这是文件14/样式(在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>
这是我的清单的一部分:
<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" >
我该怎么做?注意:我使用的是支持库,应用程序支持api-9 1:https://developer.android.com/training/basics/actionbar/styling.html#AndroidThemes
发布于 2015-05-27 11:41:23
我设计的操作栏如下所示:我创建了一个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>
然后在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);
}
我希望这能帮你找到你想要的
发布于 2015-05-27 11:42:09
如果您想要对您的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);
在文本视图中,添加您想要添加到actionBar中的任何样式或项,它将工作得很好。
https://stackoverflow.com/questions/30481013
复制相似问题