android - `android:breadCrumbShortTitle` 和 `android:breadCrumbTitle` 的区别
问题描述
在阅读android.R.attr文档时,我发现了breadCrumbTitle
and breadCrumbShortTitle
。这2个属性有什么用?android 是否在平台基础中提供了一个 breadCrumb 视图,如果有,它是什么样子的?为什么这两个属性存在?
解决方案
它们用于PreferenceActivity
:
sa.peekValue(com.android.internal.R.styleable.PreferenceHeader_breadCrumbTitle);
具体来说,它们是在从XML 文件PreferenceActivity.Header
中提取的实例上设置的: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 级别上使用的,等等。官方的设置指南甚至没有提到它们。
还有一个概念,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);
}
}
推荐阅读
- javascript - 正则表达式在找到结束之前找到开始而不是任何字符
- java - JTable getModel().setValueAt 从数组中删除第一个元素
- c++ - c ++中的模板通用引用无法编译
- javascript - 尝试使用 forloop 在 html dom 中创建乘法 div
- reactjs - 如何解决在地图函数中获取更多数据的问题
- django - CircleCI 上的 Selenium 测试失败
- sql - 获取 SQL 查询的结果并将其移动到另一个表
- python-3.x - Python中的爬虫,urlopen不起作用
- php - 删除或更改帖子或评论的状态 php,sql
- python - 降低计算精度以加快执行速度