代码之家  ›  专栏  ›  技术社区  ›  user8389458

“android:breadCrumbShortTitle”和“android:breadCrumbTitle”之间的区别`

  •  1
  • user8389458  · 技术社区  · 7 年前

    当我在读 android.R.attr 文档,我发现 breadCrumbTitle breadCrumbShortTitle .这两个属性的用法是什么?android是否在platform base中提供面包屑视图?如果是,它是什么样子的?为什么这2个属性存在?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Adam S    7 年前

    它们用于 PreferenceActivity :

    sa.peekValue(com.android.internal.R.styleable.PreferenceHeader_breadCrumbTitle);
    

    具体来说,他们是 PreferenceActivity.Header 正在从 preference_headers XML文件:

    tv = sa.peekValue(com.android.internal.R.styleable.PreferenceHeader_breadCrumbTitle);
    if (tv != null && tv.type == TypedValue.TYPE_STRING) {
        if (tv.resourceId != 0) {
            header.breadCrumbTitleRes = tv.resourceId;
        } else {
            header.breadCrumbTitle = tv.string;
        }
    }
    

    不幸的是,关于这个特性的功能的文档很少——它在哪里显示,如何在不同的API级别上使用,等等 official Settings guide 甚至没有提到他们。

    还有一个概念 FragmentBreadCrumbs 但这似乎没有使用这个属性(而且记录得更加稀少!)。

    编辑 :进一步看,这些功能是协同工作的!如果首选项标题设置了面包屑,则这些面包屑将与 碎面包屑 widget,假设存在一个id为 android.R.id.title ,则, 我们在多窗格首选项页面中:

    /**
     * Change the base title of the bread crumbs for the current preferences.
     * This will normally be called for you.  See
     * {@link android.app.FragmentBreadCrumbs} for more information.
     */
    public void showBreadCrumbs(CharSequence title, CharSequence shortTitle) {
        if (mFragmentBreadCrumbs == null) {
            View crumbs = findViewById(android.R.id.title);
            // For screens with a different kind of title, don't create breadcrumbs.
            try {
                mFragmentBreadCrumbs = (FragmentBreadCrumbs)crumbs;
            } catch (ClassCastException e) {
                setTitle(title);
                return;
            }
            if (mFragmentBreadCrumbs == null) {
                if (title != null) {
                    setTitle(title);
                }
                return;
            }
            if (mSinglePane) {
                mFragmentBreadCrumbs.setVisibility(View.GONE);
                // Hide the breadcrumb section completely for single-pane
                View bcSection = findViewById(com.android.internal.R.id.breadcrumb_section);
                if (bcSection != null) bcSection.setVisibility(View.GONE);
                setTitle(title);
            }
            mFragmentBreadCrumbs.setMaxVisible(2);
            mFragmentBreadCrumbs.setActivity(this);
        }
        if (mFragmentBreadCrumbs.getVisibility() != View.VISIBLE) {
            setTitle(title);
        } else {
            mFragmentBreadCrumbs.setTitle(title, shortTitle);
            mFragmentBreadCrumbs.setParentTitle(null, null, null);
        }
    }