我有一个包含2个布局的活动的应用程序:
通常,我会检查功能的详细信息:
if (findViewById(R.id.application_detail_container) != null) {
// The detail container view will be present only in the
// large-screen layouts (res/values-w900dp).
// If this view is present, then the
// activity should be in two-pane mode.
mTwoPane = true;
}
Run Code Online (Sandbox Code Playgroud)
如何将此类方法转换为使用数据绑定?
您只需在strings.xml文件中定义资源即可
在values/strings.xml中.
<bool name="is_tablet">false</bool>
Run Code Online (Sandbox Code Playgroud)
在values-w900dp/string.xml中
<bool name="is_tablet">true</bool>
Run Code Online (Sandbox Code Playgroud)
从代码中的任何位置访问此资源.这应该可以解决您的问题.
例如 :
boolean isTablet = getResources().getBoolean(R.bool.is_tablet);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1950 次 |
| 最近记录: |