首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在android中设置actionbar的样式

在android中设置actionbar的样式
EN

Stack Overflow用户
提问于 2015-05-27 11:22:00
回答 2查看 84关注 0票数 2

我正在按照developers.android站点上的文档来自定义我的操作栏。

问题是动作条不接受我做的样式。这是文件14/样式(在4.3 android版本设备上进行测试):

代码语言:javascript
运行
复制
<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> 

这是我的清单的一部分:

代码语言:javascript
运行
复制
<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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-05-27 11:41:23

我设计的操作栏如下所示:我创建了一个custom_action_bar.xml

代码语言:javascript
运行
复制
 <?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中,在我的活动中,我调用了这个方法:

代码语言:javascript
运行
复制
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);
}

我希望这能帮你找到你想要的

票数 0
EN

Stack Overflow用户

发布于 2015-05-27 11:42:09

如果您想要对您的actionBar进行样式设置,还有另一种简单的方法可以实现。

代码语言:javascript
运行
复制
 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中的任何样式或项,它将工作得很好。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30481013

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档