这个项目的目的是提供一个可重用的操作栏组件。操作栏模式在Android的模式是有据可查的。
操作栏组件是一个图书馆项目。这意味着,有没有需要复制粘贴到自己的项目资源,只需将动作栏组件作为一个参考的任何项目。
需要你的动作条的图标? ,已经移植奥洛夫Brickarp的一些机器人矢量格式的原生图标。http://www.yay.se/2011/02/native-android-icons-in-vector-format/
用法:
在布局中:
<com.markupartist.android.widget.ActionBar android:id="@+id/actionbar" app:title="@string/some_title" style="@style/ActionBar" />
在你的Activity:
ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar); // You can also assign the title programmatically by passing a // CharSequence or resource id. //actionBar.setTitle(R.string.some_title); actionBar.setHomeAction(new IntentAction(this, HomeActivity.createIntent(this), R.drawable.ic_title_home_default)); actionBar.addAction(new IntentAction(this, createShareIntent(), R.drawable.ic_title_share_default)); actionBar.addAction(new ToastAction());
ActionBar中自带了一个方便的IntentAction,使得它很容易创建行动的意图。要创建自定义操作,简单地实现了Action接口,并建立你自己喜欢吐司的例子下面。
private class ToastAction implements Action { @Override public int getDrawable() { return R.drawable.ic_title_export_default; } @Override public void performAction(View view) { Toast.makeText(OtherActivity.this, "Example action", Toast.LENGTH_SHORT).show(); } }
要处理的标题上点击一个android.view.View.OnClickListener传递动作栏上的方法setOnTitleClickListener的。传递的onClick认为是被分配到TextView中的标题。
actionBar.setOnTitleClickListener(new OnClickListener() { public void onClick(View v) { // Your code here } });
由于在ActionBar库“项目的所有资源将被合并到项目中,引用在ActionBar。主体工程中的值将始终使用预设值才会在ActionBar。
如果你不喜欢默认的颜色colors.xml的文件中定义的只是覆盖colors.xml的主要项目文件中的默认值。要创建一个蓝色的ActionBar创建一个colors.xml文件看起来像下面的东西的。请注意,我们不重写值actionbar_background_item_pressed_start和actionbar_background_item_pressed_end因为我们决定坚持使用默认值。
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="actionbar_separator">#3A5FCD</color> <color name="actionbar_background_start">#3A5FCD</color> <color name="actionbar_background_end">#27408B</color> </resources>
它是稳定的吗?
的确是这样,但谁也不能保证。然而,该API仍然没有稳定,所以请检查所有提交自上次拉动。它也可能是一个好主意,这个组件,而不是直接依赖于您自己的叉子。最终将有更多的控制释放,但在那之前。
您使用的是这个小部件?
要使用它的应用程序在画廊展出?然后,请发送您的应用程序的截图和细节到约翰·尼尔森。
捐款:
这个小工具是不一样的,没有卓越贡献;
ohhorob,https://github.com/ohhorob
denravonska,https://github.com/denravonska
rpdillon,https://github.com/rpdillon
RickardPettersson,https://github.com/RickardPettersson
杰克沃顿商学院,https://github.com/JakeWharton
杰西·文森特,http://blog.fsck.com
Gyuri克雷尔,http://gyurigrell.com
想做出贡献吗?
GitHub上有一些伟大的文章如何开始使用Git和GitHub上,以及如何fork一个项目。
贡献者推荐到餐桌GitHub上的应用程序(但不要有太多)。创建一个特性分支,分支推到git的枢纽,按拉的请求,写一个简单的解释。
每提交一个修复。如果说一个提交关闭打开的问题12。只需添加关闭#12你的提交信息自动的关闭问题。
所有贡献的代码必须符合Apache许可证2.0。
代码风格指引:
贡献者建议遵循了Android的代码风格指引线的长度,我尝试持有至80列,在可能的情况下例外。
总之;
缩进4个空格,没有标签。
线路长度:80列
字段名称:非公开,非静态字段以m开始。
括号:开放括号不要去上自己的行。
缩略语词:治疗词语的名字的首字母缩写,产生的XmlHttpRequest中,getURL()等
一致性:看看你周围的什么!
玩得开心,还记得我们在课余时间,所以不要太严重了:)
许可证:
版权所有(c)2010约翰·尼尔森
根据Apache许可证2.0版授权
以下为英文原文:
This projects aims to provide a reusable action bar component. The action bar pattern is well documented atAndroid Patterns.
The action bar component is an Library Project. This means that there's no need to copy-paste resources into your own project, simply add the action bar component as a reference to any project.
Need icons to your action bar? Olof Brickarp has ported some of Androids native icons to vector format.
<com.markupartist.android.widget.ActionBar
android:id="@+id/actionbar"
app:title="@string/some_title"
style="@style/ActionBar"
/>
The use of app:title
is optional, it's also possible to assign the title using the setTitle
programmatically on the ActionBar
. To be able to use the more convenient app:title
the application namespace must be included in the same manner as the android namespace is. Please refer to the layout other.xml in the example project for a full example. Again, note that it's the application namespace and not the actionbar namespace that must be referred like xmlns:app="http://schemas.android.com/apk/res/you.application.package.here"
.
ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar);
// You can also assign the title programmatically by passing a
// CharSequence or resource id.
//actionBar.setTitle(R.string.some_title);
actionBar.setHomeAction(new IntentAction(this, HomeActivity.createIntent(this), R.drawable.ic_title_home_default));
actionBar.addAction(new IntentAction(this, createShareIntent(), R.drawable.ic_title_share_default));
actionBar.addAction(new ToastAction());
ActionBar comes with a convenient IntentAction that makes it easy to create action out of Intents. To create custom actions simply implement the Action interface and build your own like the Toast example below.
private class ToastAction implements Action {
@Override
public int getDrawable() {
return R.drawable.ic_title_export_default;
}
@Override
public void performAction(View view) {
Toast.makeText(OtherActivity.this,
"Example action", Toast.LENGTH_SHORT).show();
}
}
To handle on clicks on the title pass a android.view.View.OnClickListener
to the methodsetOnTitleClickListener
on the action bar. The View
that is passed in onClick
is the TextView
that the title is assigned to.
actionBar.setOnTitleClickListener(new OnClickListener() {
public void onClick(View v) {
// Your code here
}
});
Since the ActionBar is an Libary Project all resources will be merged to the project that referencing the ActionBar. The values in the main project will always be used before the default values of the ActionBar.
If you don't like the default colors that is defined in the colors.xml file simply override the default values in the main projects colors.xml file. To create a blue ActionBar create a colors.xml file that looks something like the one below. Note that we don't override the values for actionbar_background_item_pressed_start
andactionbar_background_item_pressed_end
since we decided to stick with the default values.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="actionbar_separator">#3A5FCD</color>
<color name="actionbar_background_start">#3A5FCD</color>
<color name="actionbar_background_end">#27408B</color>
</resources>
The same can be done with the drawables, layouts and everything else that is located in the ActionBar project.
Yes it is, but there's no guarantees. The api however is still not stable so please check all commits since the last pull. It might also be an good idea to depend on your own fork instead of this component directly. Eventually there will be more controlled releases but until then.
Want to be featured in a gallery of apps using it? Then please send a screenshot and details of your app to Johan Nilsson.
This widget wouldn't be the same without the excellent contributions by;
GitHub has some great articles on how to get started with Git and GitHub and how to fork a project.
Contributers are recommended to fork the app on GitHub (but don't have too). Create a feature branch, push the branch to git hub, press Pull Request and write a simple explanation.
One fix per commit. If say a a commit closes the open issue 12. Just add closes #12
in your commit message to close that issue automagically.
All code that is contributed must be compliant with Apache License 2.0.
Contributers are recommended to follow the Android Code Style Guidelines with exception for line length that I try to hold to 80 columns where possible.
In short that is;
Have fun and remember we do this in our spare time so don't be too serious :)
Copyright (c) 2010 Johan Nilsson
Licensed under the Apache License, Version 2.0