[英]Android tab bar with different fragments and different action bar icons
I'm using tab activity with action bar. 我正在使用带有操作栏的标签活动。 In the HOME tab I have
GridView
which contains some items, like it is shown in the image below (Hot Lines, Taxi, Restaurants etc) 在HOME选项卡中,我有
GridView
,其中包含一些项目,如下图所示(热线,出租车,餐馆等)
Wen user click on the items in the grid view I want my application to take following actions: Wen用户点击网格视图中的项目我希望我的应用程序采取以下操作:
Like it is shown in the image below: 如下图所示:
As I never deal with this kind of problems can you please give me example or share some link with me of how I can do this? 由于我从不处理这类问题,请你举个例子或与我分享一些如何做到这一点的链接? and can I do this at all?
我可以这样做吗?
This might help: Android studio - is possible to add tabs pointing to fragments from designer? 这可能会有所帮助: Android studio - 是否可以添加指向设计师片段的标签? It is not exactly what you want, but a good start.
这不是你想要的,但是一个好的开始。 If you are willing to put a bit of work in it, you should be able to get what you want.
如果你愿意做一些工作,你应该能够得到你想要的东西。 If you have a basic Frame to work with and more specific problems with this matter I will gladly help you out ^^
如果你有一个基本的框架与这个问题和更具体的问题,我会很乐意帮助你^^
John 约翰
The first link you can check is THIS . 您可以检查的第一个链接是这个 。
And you should read more about ActionBar . 你应该阅读更多关于ActionBar的内容 。
The last thing is it's better if you google it first and try to write a code and when you got stuck somewhere share your code with us and ask for help. 最后一件事是,如果你首先谷歌它并尝试编写代码,当你遇到某个地方并与我们分享你的代码并寻求帮助时,它会更好。
You have to use actionbarsherlock library for it. 你必须使用actionbarsherlock库。
use android.support.v4.app.FragmentTabHost
and TabWidget
in the xml as shown below : 在xml中使用
android.support.v4.app.FragmentTabHost
和TabWidget
,如下所示:
<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
style="@style/yourstyle"/>
<FrameLayout
android:id="@+id/realtabcontent"
style="@style/realtabFrameContentStyle" />
<TabWidget
android:id="@android:id/tabs"
style="@style/yourtabstyle" />
</android.support.v4.app.FragmentTabHost>
Use SherlockFragmentActivity for showing the tabs. 使用SherlockFragmentActivity显示选项卡。
In the activities code use following code (preferably in a function) to set the ctionbar icon and text : 在活动代码中使用以下代码(最好在函数中)来设置ctionbar图标和文本:
activity.getSupportActionBar().setDisplayShowCustomEnabled(true);
activity.getSupportActionBar().setCustomView(R.layout.your_action_barlayout);
((TextView) (activity.getSupportActionBar().getCustomView().findViewById(R.id.action_bar_title))).setText("your title");
ImageView homeButton = ((ImageView) (activity.getSupportActionBar().getCustomView().findViewById(R.id.your_icon)));
homeButton.setVisibility(View.VISIBLE);
homeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, YourHOmeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
activity.startActivity(intent);
activity.finish();
}
});
ActionBar mActionBar = activity.getSupportActionBar();
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
mActionBar.show();
then call this function with your icon and your text in your fragments onResume()
method. 然后在片段
onResume()
方法中使用您的图标和文本调用此函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.