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

时间:2018-05-10 04:45:14

标签: android

在我阅读android.R.attr文档时,我找到了breadCrumbTitlebreadCrumbShortTitle。这两个属性的用途是什么? android是否在平台基础上提供了breadCrumb视图,如果是这样,它看起来像什么?为什么存在这两个属性?

1 个答案:

答案 0 :(得分:1)

他们在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的概念,但似乎没有使用此属性(并且更加稀疏地记录!)。

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