发布网友 发布时间:2022-04-14 22:07
共2个回答
懂视网 时间:2022-04-15 02:28
本来想自己写的, 怎么都觉得没有这篇写的好, 就贴个链接了: http://www.samcoles.co.uk/mobile/android-use-greendroid-to-implement-an-actionbar/ This post covers the basics of setting up a project using the GreenDroid library including pullin
本来想自己写的, 怎么都觉得没有这篇写的好, 就贴个链接了:
http://www.samcoles.co.uk/mobile/android-use-greendroid-to-implement-an-actionbar/
This post covers the basics of setting up a project using the GreenDroid library including pulling it from GitHub and how to use the ActionBar it provides. GreenDroid is a useful UI library for Android developed by Cyril Mottier. You can check out all the
features it provides by downloading the GDCatalog app from the Android Market.
The action bar:
is located at the top of the screen to support navigation and highlight important functionalities
replaces the title bar (which is often included into it)
is best used for actions across your app, like search, refresh and compose
can provide a quick link to app home by tapping the app logo
is preferably not contextual, but actions can differ from page to page
Android Patterns
If you don’t have EGit in Eclipse. You’ll need to install it. See here. Begin by opening the “Git Repository Exploring” perspective. Window > Open Perspective. Click the button for “Clone a Git Repository and add the clone to this view” and paste in this to
the URI field: https://github.com/cyrilmottier/GreenDroid.git – the rest of the details should be filled in automatically, so hit next and follow the wizard through. It’s likely you won’t need to change anything.
You’ll notice the GreenDroid repository is now available to you. Open out the branches GreenDroid > Working directory, right click the folder ‘GreenDroid’ and select ‘Import Projects’. Follow the dialog through and click finish. Switch back to the Java Perspective
and you will now have the GreenDroid project imported. You will likely have a problem with the project’s ‘gen’ folder or R.java. If you do (an exclamation mark or cross next to the project name), delete it and then recreate a new folder called gen, if not,
create the folder. I also had to right click the project, Android Tools > Fix Project Properties to get it working as it was targeting a different compiler version to mine.
Next up create your new Android Project, the build target will need to be a minimum of 1.6 to use GreenDroid. Right click on your newly created project, select Properties, then select Android on the left hand side of the dialog. At the bottom of the window
you can click “Add..” and you should have the option to select GreenDroid as a library. Click OK.
Change your default Activity to extend GDActivity. Wherever you want to use the GreenDroid ActionBar your class will need to extend GDActivity, GDListActivity or GDTabActivity. You will also need to remember to no longer call setContentView() to set your layout
and instead use setActionBarContentView(). The former will crash your Activity. Change these and hit ctrl+shift+o to organise your imports.
public class GreenDroidActionBarExampleActivity extends GDActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setActionBarContentView(R.layout.main); } }
public class GDActionBarExampleApplication extends GDApplication { @Override public Class> getHomeActivityClass() { return GreenDroidActionBarExampleActivity.class; } @Override public Intent getMainApplicationIntent() { return new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.app_url))); } }
http://www.samcoles.co.uk
addActionBarItem(Type.Info, ACTION_BAR_INFO);
private static final int ACTION_BAR_INFO = 0;
@Override public boolean onHandleActionBarItemClick(ActionBarItem item, int position) { switch(item.getItemId()) { case ACTION_BAR_INFO: startActivity(new Intent(this, InfoActivity.class)); break; default: return super.onHandleActionBarItemClick(item, position); } return true; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setActionBarContentView(R.layout.main); setTitle(R.string.info_activity_title); }
App Info
热心网友 时间:2022-04-14 23:36
我敢肯定你对这个标题肯定心存疑惑,但事实就是如此,这个标题完全适合 Android 开发人员。据我所知, Android 程序员不情愿写 findViewById ()、点击事件监听等重复率较高的代码。那我们如何才能缩短编写业务逻辑代码的时间,并且避免写那些重复的代码呢?所以让我们来成为一个能偷懒又有高效率的 Android 程序员。想知道怎么做吗?不用急,接下来我就会写到。 有许多第三方的库和框架是可供我们使用。出于种种原因,我们并不知道这些库或者知道但还没用过。有的开发者开发了自己定义的库或者并不想使用第三方的库。如果我们在应用程序开发的过程中使用一些第三方库,也许可以提高程序的可兼容性、漂亮的 UI 界面、让代码变得整洁等等。所以,我将研究更多像这样的第三方库来帮助初学者和有经验的开发人员。 今天,让我们来讨论下“依赖注入函数库”。 什么是依赖注入? 依赖注入是一种软件设计模式,无论是在运行时还是在编译时,允许删除、改变硬编码依赖性。[来自 Wikipedia](维基百科资源): 少量的代码让 Android 开发人员省力同时,也让他们能更专注于实际的业务逻辑。 RoboGuice 和 ActionBarSherlock 正如我前面提到的,你得在 RoboActivity 和 RoboFragment 中继承其中一个才能在 Activity 事件或 Fragment 中使用 RoboGuice。但是如果你已经在项目中使用了 ActionBarSherlock 去编译呢?那问题就在于,你已经继承了 SherlockActivity 或 SherlockFragmentActivity 中的一个。现在问题是,你不能同时使用 RoboGuice 和 ActionBarSherlock。 解决方法是,为 Activities 和 Fragments 定义一个基类。然后你就能同时使用 RoboGuice 和 ActionBarSherlock 了。