标签: android-tabhost

我如何使用tabHost for Android

我查看了Stack Overflow上的帖子以及其他网站上的教程,我无法理解如何使用TabHost.有人可以向我解释一下,也许可以给我一个教程链接吗?

java xml android android-tabhost

18
推荐指数
2
解决办法
5万
查看次数

Android FragmentTabHost - 尚未完全出炉?

我想看看是否有人使用新的Android API级别17附带的FragmentTabHost自定义选项卡.

我很高兴能够在我的ViewPager SherlockFragments中嵌入一个tabHost,但是我很难做一些简单的事情,例如将标签移动到底部或更改标签的布局.

有谁见过使用这个功能的好例子?

这是我在Android文档中找到的唯一示例,而且几乎没有任何描述它的用法.它似乎也忽略了布局中定义的内容R.id.fragment1.

我想我的问题是,如果有人遇到过一个很好的教程:FragmentTabHost或者他们是否知道如何a)将嵌套标签置于底部或b)更改所述标签的布局.

我已经尝试了所有常用方法,但由于看起来XML布局文件被覆盖,我没有太多运气.

private FragmentTabHost mTabHost;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    setContentView(R.layout.fragment_tabs);
    mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
    mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);

    mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"),
            FragmentStackSupport.CountingFragment.class, null);
    mTabHost.addTab(mTabHost.newTabSpec("contacts").setIndicator("Contacts"),
            LoaderCursorSupport.CursorLoaderListFragment.class, null);
    mTabHost.addTab(mTabHost.newTabSpec("custom").setIndicator("Custom"),
            LoaderCustomSupport.AppListFragment.class, null);
    mTabHost.addTab(mTabHost.newTabSpec("throttle").setIndicator("Throttle"),
            LoaderThrottleSupport.ThrottledLoaderListFragment.class, null);

    return mTabHost;
}
Run Code Online (Sandbox Code Playgroud)

在做了一些研究后,似乎可能会在支持库中初始化FragmentTabHost时出现故障.Google代码上的用户提供了以下建议:

FragmentTabHost.java

private void initFragmentTabHost(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs,
            new int[] { android.R.attr.inflatedId }, 0, 0);
    mContainerId = a.getResourceId(0, 0);
    a.recycle();

    super.setOnTabChangedListener(this);

    // If owner hasn't made its own …
Run Code Online (Sandbox Code Playgroud)

java android android-tabhost android-fragments

18
推荐指数
1
解决办法
2万
查看次数

从FragmentTabHost获取对嵌套片段的引用

在我的应用程序中,我使用了Activity一个Fragment包含FragmentTabHost它的所有选项卡nested Fragments.

内部的Activity,其保持Fragment与它nested Fragment,我们可以得到一个连接使用参考onAttachedFragment().

可是如何才能让一个参考nested FragmentFragmentTabHost

android android-tabhost android-fragments android-nested-fragment

18
推荐指数
2
解决办法
2万
查看次数

FragmentPagerAdapter - 当用户转到新标签时如何检测滑动或标签点击?

我有一个MainActivity有三个片段FragmentPagerAdapter如下所示.如何通过滑动或单击选项卡,如何找出用户从第一个片段到第二个片段或从第二个片段到第二个片段的时间?我看到这个getItem()方法并没有像我声明的那样被调用mViewPager.setOffscreenPageLimit(2);

public class MainThreeTabAdapter extends FragmentPagerAdapter {

    private final String[] CONTENT = new String[]{"News", "Rewards", "Me"};

    public MainThreeTabAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        if (position == 0) {
            return NewsFragment.newInstance();
        } else if (position == 1) {
            return RewardsFragment.newInstance();
        } else if (position == 2) {
            return MeFragment.newInstance(true, App.getAccountData().getId());
        } else {
            return null;
        }

    }

    @Override
    public CharSequence getPageTitle(int position) {
        return CONTENT[position % CONTENT.length];
    } …
Run Code Online (Sandbox Code Playgroud)

android android-tabhost android-fragments android-viewpager android-pageradapter

18
推荐指数
1
解决办法
2万
查看次数

如何从TabHost引用子活动来调用公共函数?

我有一个带有两个子活动的TabHost(在两个标签中).我还在其中一个活动中实现了一个公共函数,我想从我的父母(TabHost)调用,以触发选项卡中的某些操作.

是否可以从TabHost引用活动本身来调用公共函数?

谢谢

这是我的tabhost设置:

    res = getResources(); 
    tabHost = getTabHost(); 

    TabHost.TabSpec spec; 
    Intent intent;  

    intent = new Intent().setClass(this, home.class);
    spec = tabHost.newTabSpec("home").setIndicator("Groups", res.getDrawable(R.drawable.groups)).setContent(intent);
    tabHost.addTab(spec);
    intent = new Intent().setClass(this, messages.class);
    spec = tabHost.newTabSpec("messages").setIndicator("Messages", res.getDrawable(R.drawable.messages)).setContent(intent);    
    tabHost.addTab(spec);
Run Code Online (Sandbox Code Playgroud)

android android-tabhost android-activity

17
推荐指数
4
解决办法
1万
查看次数

FragmentTabHost - 没有标签为null的标签

前几天,我实现TabHostFramgentFragment一个NavigationDrawer,和我面临的是以下错误的问题:

java.lang.IllegalStateException:没有标记null的标签

事情是所有的工作完美,因为我的第一个项目列表NavigationDrawer是我的TabHostFragment,所以它工作完美,但问题是当我进入第二个项目的例子然后我想回到第一个项目,每次我试试它崩溃了.

我在寻找随处可见,在这里SO,code.google.com等...我仍然没有得到正确的答案.

tab_host_test_2.xml看起来像:

  <android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="0" />

        <FrameLayout
            android:id="@+id/realtabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1" />
    </LinearLayout>

</android.support.v4.app.FragmentTabHost>
Run Code Online (Sandbox Code Playgroud)

activity_main.xml在哪里看到我的NavigationDrawer样子:

 <android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Framelayout to display Fragments -->
    <FrameLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


    <!-- Listview to display slider menu …
Run Code Online (Sandbox Code Playgroud)

java android android-layout android-tabhost android-viewpager

17
推荐指数
2
解决办法
1万
查看次数

Android 1.6&Fragment&Tabhost

我正在努力升级Android应用程序(1.6兼容性),该应用程序使用a TabHost来显示3个带有嵌套活动的不同选项卡.

当时我使用ActivityGroup技巧在选项卡中显示嵌套活动,但我对这种方法非常不满意,因为处理某些功能真的很痛苦.

我听说过针对1.6的Fragments API兼容包,Fragment看起来非常适合我想要做的事情(在带有过渡效果和东西的标签中显示嵌套视图/功能)但是我不能让它与它一起工作TabHost(它的意思是使用,Action Bar但在兼容包中没有.

你们有没有人找到在你的应用程序中创建这样一个结构的方法?

我的错误是:

ERROR/AndroidRuntime(955): Caused by: java.lang.RuntimeException: Unable
Run Code Online (Sandbox Code Playgroud)

启动活动ComponentInfo {com.XXX}:java.lang.IllegalArgumentException:找不到片段MyFragment的id 0x1020011的视图

main.xml中

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:layout_weight="1" />

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0" />

    </LinearLayout>

</TabHost>
Run Code Online (Sandbox Code Playgroud)

MainActivity.java

public class MainActivity extends TabActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        Resources res = getResources();
        final TabHost tabs = getTabHost(); 
        TabHost.TabSpec spec;
        Intent i;

        i …
Run Code Online (Sandbox Code Playgroud)

java android android-tabhost activitygroup android-fragments

16
推荐指数
1
解决办法
9915
查看次数

android:使用ActivityGroup嵌入活动

我在构建应用程序的概念化/设计阶段,我遇到了一些障碍.基本上我正在寻找一种方法将一个活动嵌入到另一个活动的UI中,类似于TabHost/TabActivity.屏幕顶部会有一个窗口,其中包含其他活动,下面是一个独立于上述活动的按钮和控件,应该始终可见.用户将能够在窗口中从一个活动导航到另一个活动,而不会对以下控件进行任何更改.

在调查问题时,我遇到了ActivityGroup,看起来它会很有用,但我将如何实现呢?任何人都有使用ActivityGroup的经验或有其他想法吗?

embed android embedding android-tabhost android-activity

15
推荐指数
1
解决办法
2万
查看次数

Android异常:您是否忘记调用'public void setup(LocalActivityManager activityGroup)'

mycode的:

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final TabHost tabHost = (TabHost) findViewById(R.id.tabhost);

//      LocalActivityManager mLocalActivityManager = new LocalActivityManager(this, false);
        tabHost.setup();

        TabSpec tabSpecCheckIn = tabHost.newTabSpec(getResources().getText(R.string.button_check_in).toString());

        tabSpecCheckIn.setIndicator(getResources().getText(R.string.button_check_in).toString(), getResources().getDrawable(android.R.drawable.star_off));
        tabSpecCheckIn.setContent(R.id.check_in);
        tabHost.addTab(tabSpecCheckIn);

        TabSpec tabSpecReview = tabHost.newTabSpec(getResources().getText(R.string.button_review).toString());
        tabSpecReview.setIndicator(getResources().getText(R.string.button_review).toString(), getResources().getDrawable(android.R.drawable.star_off));
        tabSpecReview.setContent(R.id.review);
        tabHost.addTab(tabSpecReview);

        TabSpec tabSpecMyCircles = tabHost.newTabSpec(getResources().getText(R.string.button_my_circles).toString());
        tabSpecMyCircles.setIndicator(getResources().getText(R.string.button_my_circles).toString(), getResources().getDrawable(android.R.drawable.star_off));
        tabSpecMyCircles.setContent(R.id.my_circle);
        tabHost.addTab(tabSpecMyCircles);

        TabSpec tabSpecMySettings = tabHost.newTabSpec(getResources().getText(R.string.button_settings).toString());
        tabSpecMySettings.setIndicator(getResources().getText(R.string.button_settings).toString(), getResources().getDrawable(android.R.drawable.star_off));
        tabSpecMySettings.setContent(new Intent(this,CheckInActivity.class));
        tabHost.addTab(tabSpecMySettings);

        tabHost.setCurrentTab(0);
    }
}
Run Code Online (Sandbox Code Playgroud)

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TabHost android:id="@+id/tabhost"
        android:layout_width="fill_parent" android:layout_height="fill_parent">

        <TabWidget android:layout_width="fill_parent" …
Run Code Online (Sandbox Code Playgroud)

android exception android-tabhost

15
推荐指数
2
解决办法
3万
查看次数

FragmentTabHost - 在第一次查看之前,标签不可寻址

我使用的是多选项卡的FragmentTabHost(构造如图所示这里).但是,我无法使用getFragmentByTag(在这种情况下返回null)随机地查找我的选项卡,除非通过至少单击选项卡一次激活已解决的选项卡.

FragmentTabHost似乎延迟了标签的创建,直到我们确实需要它们(也就是用户点击它并想要查看它).
有没有办法强制主机立即创建它们,以便我可以通过getFragmentByTag安全地访问它们?
或者是否可以"自己创建"标签并将它们添加到TabHost?

android android-tabhost android-fragments

15
推荐指数
1
解决办法
233
查看次数