我有一个包含2个布局的活动的应用程序:
> layout / activity_main.xml – “手机模式”,里面有一个视图(列表)
> layout-w900dp / activity_main.xml – “平板电脑模式”,包含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;
}
如何将此类方法转换为使用数据绑定?
解决方法:
您只需在strings.xml文件中定义资源即可
在values / strings.xml中.
false
在values-w900dp / string.xml中
true
从代码中的任何位置访问此资源.这应该可以解决您的问题.
For example :
boolean isTablet = getResources().getBoolean(R.bool.is_tablet);
标签:android
来源: https://codeday.me/bug/20190727/1554586.html