在阅读android.R.attr文档时,我发现了breadCrumbTitlebreadCrumbShortTitle。这两个属性的用途是什么? android是否在平台基础上提供了BreadCrumb视图,如果是的话,它是什么样的?为什么这2个属性存在?

最佳答案

它们用在PreferenceActivity中:

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


具体来说,它们是在从PreferenceActivity.Header XML文件中拉出的preference_headers实例上设置的:

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的概念,但是似乎没有使用此属性(并且文献更加稀疏!)。

编辑:进一步看,事实证明这些功能协同工作!如果首选项标头设置了面包屑,那么这些面包屑将与FragmentBreadCrumbs小部件一起使用,假定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);
    }
}

08-17 02:07