一、自定义MenuItem的视图

custom_view.xml (就是一个单选按钮)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="left|center_vertical"
android:orientation="horizontal"
>
<RadioGroup
android:id="@+id/radio_nav"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<RadioButton
android:text="Custom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
/>
<RadioButton
android:text="View!"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
/>
</RadioGroup>
</LinearLayout>

MainActivity.java

//Inflate the custom view
View customNav = LayoutInflater.from(this).inflate(R.layout.custom_view, null);
//Bind to its state change
((RadioGroup)customNav.findViewById(R.id.radio_nav)).setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
Toast.makeText(MainActivity.this, "Navigation selection changed.", Toast.LENGTH_SHORT).show();
}
}); //Attach to the action bar
getSupportActionBar().setCustomView(customNav);
getSupportActionBar().setDisplayShowCustomEnabled(true);

二、添加圆形模糊进度的进度条

package com.kale.actionbar02;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Toast; public class MainActivity extends ActionBarActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_main);
//设置actionbar上面显示进度条,true表示显示,如果是false表示不显示
setSupportProgressBarIndeterminateVisibility(true);//Attach to the action bar
getSupportActionBar().setCustomView(customNav);
getSupportActionBar().setDisplayShowCustomEnabled(true);
} }

三、添加有进度的横向进度条

package com.kale.actionbar02;

import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.Window; public class MainActivity extends ActionBarActivity {
private int mProgress = 100;
Handler mHandler = new Handler();
Runnable mProgressRunner = new Runnable() {
@Override
public void run() {
mProgress += 2;
// Normalize our progress along the progress bar's scale
int progress = (Window.PROGRESS_END - Window.PROGRESS_START) / 100* mProgress;
setSupportProgress(progress); if (mProgress < 100) {
mHandler.postDelayed(mProgressRunner, 50);
}
}
}; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
supportRequestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.activity_main);
// 设置actionbar上面显示进度条,true表示显示,如果是false表示不显示
//setSupportProgressBarVisibility(true);//设置初始状态是否显示进度条,一般我们不显示。在用的时候再显示它 findViewById(R.id.button_id).setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View arg0) {
if (mProgress == 100) {
mProgress = 0;
mProgressRunner.run();
}
}
}); } }

四、添加下拉导航+悬浮模式

给ActionBar添加下拉导航的方法都是添加一个适配器,可以使简单的ArrayAdapter,也可以使SpinnerAdapter,添加完数据后再绑定个监听器。其实和Spinner没啥太大的区别。悬浮模式是可以让布局文件从ActionBar底下通过,可以实现透明效果。其代码就一行:

     // 设置ActionBar为悬浮的,就是说悬浮在布局文件上
supportRequestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);

注意看一下布局的,上边距。是用的ActionBar的高度来指定的

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="?actionBarSize"

android:orientation="vertical"> <TextView
android:id="@+id/bunch_of_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
</FrameLayout>

下面是下拉导航的代码:

package com.kale.actionbar02;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBar.OnNavigationListener;
import android.support.v7.app.ActionBarActivity;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.widget.Toast; public class MainActivity extends ActionBarActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 设置ActionBar为悬浮的,就是说悬浮在布局文件上
supportRequestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
setContentView(R.layout.activity_main);
// 将ActionBar的操作模型设置为NAVIGATION_MODE_LIST
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
getSupportActionBar().setTitle(null); Context context = getSupportActionBar().getThemedContext();
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
context, R.array.locations,
android.R.layout.simple_spinner_dropdown_item);
getSupportActionBar().setListNavigationCallbacks(adapter,
new DropDownListenser()); // Load partially transparent black background
getSupportActionBar().setBackgroundDrawable(
getResources().getDrawable(R.drawable.bar_color)); TextView bunchOfText = (TextView) findViewById(R.id.bunch_of_text);
bunchOfText.setText(builder.toString());
} /**
* 实现 ActionBar.OnNavigationListener接口
*/
class DropDownListenser implements OnNavigationListener {
// 得到和Adapter里一致的字符数组
String[] listNames = getResources().getStringArray(R.array.locations); @Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
Toast.makeText(getApplicationContext(), listNames[itemPosition], 0)
.show();
return false;
} } }

values/array.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="locations">
<item>Home</item>
<item>Email</item>
<item>Calendar</item>
<item>Browser</item>
<item>Clock</item>
</string-array>
</resources>

全部的代码:

package com.kale.actionbar02;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBar.OnNavigationListener;
import android.support.v7.app.ActionBarActivity;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.widget.Toast; public class MainActivity extends ActionBarActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 设置ActionBar为悬浮的,就是说悬浮在布局文件上
supportRequestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
setContentView(R.layout.activity_main);
// 将ActionBar的操作模型设置为NAVIGATION_MODE_LIST
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
getSupportActionBar().setTitle(null); Context context = getSupportActionBar().getThemedContext();
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
context, R.array.locations,
android.R.layout.simple_spinner_dropdown_item);
getSupportActionBar().setListNavigationCallbacks(adapter,
new DropDownListenser()); // Load partially transparent black background
getSupportActionBar().setBackgroundDrawable(
getResources().getDrawable(R.drawable.bar_color)); StringBuilder builder = new StringBuilder();
for (int i = 0; i < 3; i++) {
for (String dialog : DIALOGUE) {
builder.append(dialog).append("\n\n");
}
} TextView bunchOfText = (TextView) findViewById(R.id.bunch_of_text);
bunchOfText.setText(builder.toString());
} /**
* 实现 ActionBar.OnNavigationListener接口
*/
class DropDownListenser implements OnNavigationListener {
// 得到和Adapter里一致的字符数组
String[] listNames = getResources().getStringArray(R.array.locations); @Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
Toast.makeText(getApplicationContext(), listNames[itemPosition], 0)
.show();
return false;
} } public static final String[] DIALOGUE = new String[] {
"So shaken as we are, so wan with care,"
+ "Find we a time for frighted peace to pant,"
+ "And breathe short-winded accents of new broils"
+ "To be commenced in strands afar remote."
+ "No more the thirsty entrance of this soil"
+ "Shall daub her lips with her own children's blood;"
+ "Nor more shall trenching war channel her fields,"
+ "Nor bruise her flowerets with the armed hoofs"
+ "Of hostile paces: those opposed eyes,"
+ "Which, like the meteors of a troubled heaven,"
+ "All of one nature, of one substance bred,"
+ "Did lately meet in the intestine shock"
+ "And furious close of civil butchery"
+ "Shall now, in mutual well-beseeming ranks,"
+ "March all one way and be no more opposed"
+ "Against acquaintance, kindred and allies:"
+ "The edge of war, like an ill-sheathed knife,"
+ "No more shall cut his master. Therefore, friends,"
+ "As far as to the sepulchre of Christ,"
+ "Whose soldier now, under whose blessed cross"
+ "We are impressed and engaged to fight,"
+ "Forthwith a power of English shall we levy;"
+ "Whose arms were moulded in their mothers' womb"
+ "To chase these pagans in those holy fields"
+ "Over whose acres walk'd those blessed feet"
+ "Which fourteen hundred years ago were nail'd"
+ "For our advantage on the bitter cross."
+ "But this our purpose now is twelve month old,"
+ "And bootless 'tis to tell you we will go:"
+ "Therefore we meet not now. Then let me hear"
+ "Of you, my gentle cousin Westmoreland,"
+ "What yesternight our council did decree"
+ "In forwarding this dear expedience.", "Hear him but reason in divinity,"
+ "And all-admiring with an inward wish"
+ "You would desire the king were made a prelate:"
+ "Hear him debate of commonwealth affairs,"
+ "You would say it hath been all in all his study:"
+ "List his discourse of war, and you shall hear"
+ "A fearful battle render'd you in music:"
+ "Turn him to any cause of policy,"
+ "The Gordian knot of it he will unloose,"
+ "Familiar as his garter: that, when he speaks,"
+ "The air, a charter'd libertine, is still,"
+ "And the mute wonder lurketh in men's ears,"
+ "To steal his sweet and honey'd sentences;"
+ "So that the art and practic part of life"
+ "Must be the mistress to this theoric:"
+ "Which is a wonder how his grace should glean it,"
+ "Since his addiction was to courses vain,"
+ "His companies unletter'd, rude and shallow,"
+ "His hours fill'd up with riots, banquets, sports,"
+ "And never noted in him any study,"
+ "Any retirement, any sequestration"
+ "From open haunts and popularity.", "I come no more to make you laugh: things now,"
+ "That bear a weighty and a serious brow,"
+ "Sad, high, and working, full of state and woe,"
+ "Such noble scenes as draw the eye to flow,"
+ "We now present. Those that can pity, here"
+ "May, if they think it well, let fall a tear;"
+ "The subject will deserve it. Such as give"
+ "Their money out of hope they may believe,"
+ "May here find truth too. Those that come to see"
+ "Only a show or two, and so agree"
+ "The play may pass, if they be still and willing,"
+ "I'll undertake may see away their shilling"
+ "Richly in two short hours. Only they"
+ "That come to hear a merry bawdy play,"
+ "A noise of targets, or to see a fellow"
+ "In a long motley coat guarded with yellow,"
+ "Will be deceived; for, gentle hearers, know,"
+ "To rank our chosen truth with such a show"
+ "As fool and fight is, beside forfeiting"
+ "Our own brains, and the opinion that we bring,"
+ "To make that only true we now intend,"
+ "Will leave us never an understanding friend."
+ "Therefore, for goodness' sake, and as you are known"
+ "The first and happiest hearers of the town,"
+ "Be sad, as we would make ye: think ye see"
+ "The very persons of our noble story"
+ "As they were living; think you see them great,"
+ "And follow'd with the general throng and sweat"
+ "Of thousand friends; then in a moment, see"
+ "How soon this mightiness meets misery:"
+ "And, if you can be merry then, I'll say"
+ "A man may weep upon his wedding-day.", "First, heaven be the record to my speech!"
+ "In the devotion of a subject's love,"
+ "Tendering the precious safety of my prince,"
+ "And free from other misbegotten hate,"
+ "Come I appellant to this princely presence."
+ "Now, Thomas Mowbray, do I turn to thee,"
+ "And mark my greeting well; for what I speak"
+ "My body shall make good upon this earth,"
+ "Or my divine soul answer it in heaven."
+ "Thou art a traitor and a miscreant,"
+ "Too good to be so and too bad to live,"
+ "Since the more fair and crystal is the sky,"
+ "The uglier seem the clouds that in it fly."
+ "Once more, the more to aggravate the note,"
+ "With a foul traitor's name stuff I thy throat;"
+ "And wish, so please my sovereign, ere I move,"
+ "What my tongue speaks my right drawn sword may prove.", "Now is the winter of our discontent"
+ "Made glorious summer by this sun of York;"
+ "And all the clouds that lour'd upon our house"
+ "In the deep bosom of the ocean buried."
+ "Now are our brows bound with victorious wreaths;"
+ "Our bruised arms hung up for monuments;"
+ "Our stern alarums changed to merry meetings,"
+ "Our dreadful marches to delightful measures."
+ "Grim-visaged war hath smooth'd his wrinkled front;"
+ "And now, instead of mounting barded steeds"
+ "To fright the souls of fearful adversaries,"
+ "He capers nimbly in a lady's chamber"
+ "To the lascivious pleasing of a lute."
+ "But I, that am not shaped for sportive tricks,"
+ "Nor made to court an amorous looking-glass;"
+ "I, that am rudely stamp'd, and want love's majesty"
+ "To strut before a wanton ambling nymph;"
+ "I, that am curtail'd of this fair proportion,"
+ "Cheated of feature by dissembling nature,"
+ "Deformed, unfinish'd, sent before my time"
+ "Into this breathing world, scarce half made up,"
+ "And that so lamely and unfashionable"
+ "That dogs bark at me as I halt by them;"
+ "Why, I, in this weak piping time of peace,"
+ "Have no delight to pass away the time,"
+ "Unless to spy my shadow in the sun"
+ "And descant on mine own deformity:"
+ "And therefore, since I cannot prove a lover,"
+ "To entertain these fair well-spoken days,"
+ "I am determined to prove a villain"
+ "And hate the idle pleasures of these days."
+ "Plots have I laid, inductions dangerous,"
+ "By drunken prophecies, libels and dreams,"
+ "To set my brother Clarence and the king"
+ "In deadly hate the one against the other:"
+ "And if King Edward be as true and just"
+ "As I am subtle, false and treacherous,"
+ "This day should Clarence closely be mew'd up,"
+ "About a prophecy, which says that 'G'"
+ "Of Edward's heirs the murderer shall be."
+ "Dive, thoughts, down to my soul: here"
+ "Clarence comes.", "To bait fish withal: if it will feed nothing else,"
+ "it will feed my revenge. He hath disgraced me, and"
+ "hindered me half a million; laughed at my losses,"
+ "mocked at my gains, scorned my nation, thwarted my"
+ "bargains, cooled my friends, heated mine"
+ "enemies; and what's his reason? I am a Jew. Hath"
+ "not a Jew eyes? hath not a Jew hands, organs,"
+ "dimensions, senses, affections, passions? fed with"
+ "the same food, hurt with the same weapons, subject"
+ "to the same diseases, healed by the same means,"
+ "warmed and cooled by the same winter and summer, as"
+ "a Christian is? If you prick us, do we not bleed?"
+ "if you tickle us, do we not laugh? if you poison"
+ "us, do we not die? and if you wrong us, shall we not"
+ "revenge? If we are like you in the rest, we will"
+ "resemble you in that. If a Jew wrong a Christian,"
+ "what is his humility? Revenge. If a Christian"
+ "wrong a Jew, what should his sufferance be by"
+ "Christian example? Why, revenge. The villany you"
+ "teach me, I will execute, and it shall go hard but I"
+ "will better the instruction.", "Virtue! a fig! 'tis in ourselves that we are thus"
+ "or thus. Our bodies are our gardens, to the which"
+ "our wills are gardeners: so that if we will plant"
+ "nettles, or sow lettuce, set hyssop and weed up"
+ "thyme, supply it with one gender of herbs, or"
+ "distract it with many, either to have it sterile"
+ "with idleness, or manured with industry, why, the"
+ "power and corrigible authority of this lies in our"
+ "wills. If the balance of our lives had not one"
+ "scale of reason to poise another of sensuality, the"
+ "blood and baseness of our natures would conduct us"
+ "to most preposterous conclusions: but we have"
+ "reason to cool our raging motions, our carnal"
+ "stings, our unbitted lusts, whereof I take this that"
+ "you call love to be a sect or scion.", "Blow, winds, and crack your cheeks! rage! blow!"
+ "You cataracts and hurricanoes, spout"
+ "Till you have drench'd our steeples, drown'd the cocks!"
+ "You sulphurous and thought-executing fires,"
+ "Vaunt-couriers to oak-cleaving thunderbolts,"
+ "Singe my white head! And thou, all-shaking thunder,"
+ "Smite flat the thick rotundity o' the world!"
+ "Crack nature's moulds, an germens spill at once,"
+ "That make ingrateful man!" }; }

源码下载:http://download.csdn.net/detail/shark0017/7688143

低版本系统兼容的ActionBar(三)自定义Item视图+进度条的实现+下拉导航+透明ActionBar的更多相关文章

  1. 低版本系统兼容的ActionBar(二)ActionProvider+分离式ActionBar+分离式的ActionMode

           这篇文章主要讲的是在低版本兼容的ActionBar中实现自定义的ActionProvider,ShareActionProvider的使用方法,如何实现分离式ActionBar,外加在分 ...

  2. 低版本系统兼容的ActionBar(一)设置颜色+添加Menu+添加ActionMode

        之前我一直用ActionBarSherlock这个开源项目来做ActionBar,因为它可以让低版本的设备也能用上ActionBar.但是在最新的SDK中Google提供了一个AppCompa ...

  3. 低版本系统兼容的ActionBar(四)添加Tab+添加自定义的Tab视图+Fragment

    在ActionBar中添加Tab是很有用的技巧.在support V7库的支持下,我们几乎可以用和之前一样的方式来添加Tab,对于Tab来说,我们可以和MenuItem一样,给他定义自己的视图.我这里 ...

  4. 低版本系统兼容的ActionBar(五)修改ActionBar的全套样式,从未如此简单过

         设定ActionBar的样式,是我们必须掌握的技能,在之前我们可能都需要一行一行的写代码,然后在模拟器上测试效果,但是现在我们有个一个很棒的工具来设定样式.设定ActionBar样式的工作从 ...

  5. 低版本系统兼容的ActionBar(七)自定义Actionbar标题栏字体

    这个自定义字体其实和ActionBar有关,但之前写AtionBar的时候没考虑到修改字体样式,今天看到一篇专门写这个的文章就贴上使用方式.╮(╯▽╰)╭,不得不说Actionbar的那个样式真是让人 ...

  6. 低版本系统兼容的ActionBar(六)用Fragment+ViewPager+Tab实现快速导航

    Tab经常和Fragment结合使用,这一讲我们用3种方式来实现这种快捷导航. 0.重要的两个监听器 MyTabListener,这个我们之前已经接触过了 package com.kale.actio ...

  7. hyperscan在低版本系统应用问题

    编译环境:centos6.3 32位/64位 由于hyperscan使用许多C++11特性,在低版本系统gcc版本不能编译.后来发现在runtime时也就是hs_scan时只需要依赖libhs_run ...

  8. Android 高版本API方法在低版本系统上的兼容性处理

    Android 版本更替,新的版本带来新的特性,新的方法. 新的方法带来许多便利,但无法在低版本系统上运行,如果兼容性处理不恰当,APP在低版本系统上,运行时将会crash. 本文以一个具体的例子说明 ...

  9. Android零基础入门第52节:自定义酷炫进度条

    原文:Android零基础入门第52节:自定义酷炫进度条 Android系统默认的ProgressBar往往都不能满足实际开发需要,一般都会开发者自定义ProgressBar. 在Android开发中 ...

随机推荐

  1. redirect模块的秘密

    所有的redirect记录都在config/url_directs下面, 但是某个node/edit的redirect记录只包含redirect到自己的记录,且不验证url的合理性. 现在比如,a跳转 ...

  2. NSS_02 日志配置

    采用log4net,使用系统推荐的最新版本:log4net-1.2.11-bin-newkey.zip(网址:http://logging.apache.org/log4net/download_lo ...

  3. v9 调用模型中新增的字段

    在模型中新增字段的时候,可以选择“是否为主表”. 若选是,则前台调用可直接通过字段名调用. 若选否,在前台调用是应在{pc:content}中添加 moreinfo="1",表示允 ...

  4. 构建 MariaDB Galera Cluster 分布式数据库集群(一)

    MariaDB Galera Cluster 介绍 简介 MariaDB集群是MariaDB同步多主机集群,仅支持XtraDB(详见本文结尾注释)/InnoDB存储引擎(虽然有对MyISAM实验支持 ...

  5. CHROME浏览器清缓存

  6. JS和Jquery获取和修改label的值

    获取值: label标签在JS和Jquery中使用不能像其他标签一样用value获取它的值: var label=document.getElementById("id");var ...

  7. OCM_第十二天课程:Section6 &mdash;》数据库性能调优_ 资源管理器/执行计划

    注:本文为原著(其内容来自 腾科教育培训课堂).阅读本文注意事项如下: 1:所有文章的转载请标注本文出处. 2:本文非本人不得用于商业用途.违者将承当相应法律责任. 3:该系列文章目录列表: 一:&l ...

  8. linux 下实用软件工具推荐

    截图:Deepin-Screenshot 音乐:deepin-music netease-music 绘图工具:Draw.io Desktop (chrome extension) / www.pro ...

  9. 【SQL Server】MS SQL Server中的CONVERT日期格式化大全

    CONVERT 函数将某种数据类型的表达式显式转换为另一种数据类型.SQL Server中 将日期格式化. SQL Server 支持使用科威特算法的阿拉伯样式中的数据格式. 在表中,左侧的两列表示将 ...

  10. python with用法举例

    我们知道在操作文件对象的时候可以这么写 with open('a.txt') as f: '代码块' 上述叫做上下文管理协议,即with语句,为了让一个对象兼容with语句,必须在这个对象的类中声明_ ...