布局文件使用中文问题

<TextView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:text='@{"姓名:" + user.name}' />  String user.name 正确
<TextView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:text='@{user.lolita ? "萝莉" : "不是萝莉"}' /> boolean user.lolita 正确
<TextView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:text='@{user.age + "岁数"}' /> int user.age 正确

注意事项
使用中文字符串相加的时候必须是偶数,如果是奇数如

<TextView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:text='@{user.age + "岁"}' />

就会编译失败


解决办法
在strings.xml 定义中文,然后在布局文件引用
android:text='@{user.age + @string/sui}'

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,705评论 25 709
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 31,780评论 18 399
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,026评论 19 139
  • 最近看Elastic-Job源码,看到它里面实现的任务运行轨迹的持久化,使用的是Guava的AsyncEventB...
    端木轩阅读 2,092评论 2 6
  • 对于这个迅雷看看 我已经不想再吐槽什么了...大半夜的寝室还没有网...文件下不下来...没有图片测不出来尺寸.....
    9妹9妹阅读 677评论 0 0