Android ActionBar标题和渐变背景

需要在AndroidManifest.xml中设置

android:theme="@style/Theme.AppCompat"

如果提示找不到,请按下图设置:

至于如何引入的方法,请看前一篇。

一。使用图片作为背景

直接在代码中引用图片即可

public class MainActivity extends ActionBarActivity {

    private ActionBar actionBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        actionBar = getSupportActionBar();

        //设置标题
        actionBar.setTitle("Bar例子");
        actionBar.setSubtitle("努力!");

        //实现用户点击ActionBar 图标后返回前一个activity
        actionBar.setDisplayHomeAsUpEnabled(true) ;

      //背景图片
        Resources res = getResources();
        Drawable myDrawable = res.getDrawable(R.drawable.top_theme_blue);
        actionBar.setBackgroundDrawable(myDrawable);
    }

二。使用渐变颜色作为背景

2.1 生成actionbar_gradient_bg.xml 文件

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

<!--
android:startColor和android:endColor分别为起始和结束颜色
android:angle是渐变角度,必须为45的整数倍。
线性渐变:
 android:type="linear"
 径向渐变 :
 android:type="radial"
 径向渐变需要指定半径如: android:gradientRadius="50"
 -->
   <gradient
       android:angle="270"
       android:endColor="#ff8c00"
       android:startColor="#FFFFFF"
       android:type="linear" />

</shape>

2.2 在代码中指定

//设置渐变色背景
        actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_gradient_bg)

				
时间: 2024-08-30 01:25:55

Android ActionBar标题和渐变背景的相关文章

android 圆角边框、渐变背景的TextView

加一个红色的边框: textView的XML: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_

android:修改PagerTabStrip中的背景颜色,标题字体的样式、颜色和图标以及指示条的颜色

1.修改PagerTabStrip中的背景颜色 我们在布局中直接设置background属性即可: <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="fill_parent" android:layout_height="fill_parent" > <android.support.v4.view.PagerTabS

Android 用属性动画自定义view的渐变背景

自定义view渐变背景,同时监听手势自动生成小圆球. 宿主Activity如下: package com.edaixi.tempbak; import java.util.ArrayList; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorSet; import android.animation.ArgbE

Android ActionBar完全解析,使用官方推荐的最佳导航栏(下)

转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/25466665 本篇文章主要内容来自于Android Doc,我翻译之后又做了些加工,英文好的朋友也可以直接去读原文. http://developer.android.com/guide/topics/ui/actionbar.html 限于篇幅的原因,在上篇文章中我们只学习了ActionBar基础部分的知识,那么本篇文章我们将接着上一章的内容继续学习,探究一下ActionBar

Android ActionBar完全解析,使用官方推荐的最佳导航栏(上)

转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/18234477 本篇文章主要内容来自于Android Doc,我翻译之后又做了些加工,英文好的朋友也可以直接去读原文. http://developer.android.com/guide/topics/ui/actionbar.html Action Bar是一种新増的导航栏功能,在Android 3.0之后加入到系统的API当中,它标识了用户当前操作界面的位置,并提供了额外的用

Android ActionBar的基本用法

本文翻译了这篇文章:Using the Android action bar (ActionBar) - Tutorial 1.ActionBar的简介ActionBar位于Activity的顶部,可用来显示activity的标题.Icon.Actions和一些用于交互的View.它也可被用于应用的导航.ActionBar 是在Android 3.0(API 11)中加入到SK中的,想在低版本中使用ActionBar有两种选择:使用http://actionbarsherlock.com 或使用

【转】Android ActionBar完全解析,使用官方推荐的最佳导航栏(上)

转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/18234477 本篇文章主要内容来自于Android Doc,我翻译之后又做了些加工,英文好的朋友也可以直接去读原文. http://developer.android.com/guide/topics/ui/actionbar.html Action Bar是一种新増的导航栏功能,在Android 3.0之后加入到系统的API当中,它标识了用户当前操作界面的位置,并提供了额外的用

自定义ActionBar标题与菜单中的文字样式

自定义标题文字样式 标题样式是ActionBar样式的一部分,所以要先定义ActionBar的样式 <style name="AppTheme" parent="AppBaseTheme"> <item name="android:actionBarStyle">@style/CustomActionBar</item> </style> 然后在ActionBar的样式中通过android:titl

Android actionbar 搜索框

就是实现在顶部这样的搜索框. 一.这个搜索框是actionbar上的menu上的一个item.叫SearchView.我们可以先在menu选项里定义好: bmap_menu.xml: <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item androi