Coder Social home page Coder Social logo

Comments (12)

WinDerek avatar WinDerek commented on June 20, 2024 1

这算是Windows下开发Android使用DataBinding的常见问题了吧。因为Windows默认使用ANSI编码,简体中文的Windows下即GBK,所以需要加一个环境变量JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8来指定Javac默认的编码。
关于JAVA_TOOL_OPTIONS环境变量
所以不需要全用@string这种方式来替代硬编码,Windows用户一样可以开心地玩耍DataBinding!
@guuguo @blackbbc @StephenGiant

from tucao.

blackbbc avatar blackbbc commented on June 20, 2024

在Databinding中,我使用了类似这样的绑定:
(取自activity_search.xml)

<TextView
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text='@{"共:" + viewModel.totalCount + "个相关结果"}'
    android:textColor="@color/secondary_text"
    android:textSize="12sp"
    android:visibility="@{viewModel.totalCountVisibility}"
    tools:text="共:274个相关结果" />

注意到android:text这一行,我使用了中文。这在Unix系统下是可以编译通过的,然而在Windows下是无法编译通过的,详见:http://blog.csdn.net/yangheng362/article/details/70186866

from tucao.

guuguo avatar guuguo commented on June 20, 2024

谢谢,已经成功跑起来了,希望作者能把中文改成@string方式,方便我们windows用户

from tucao.

StephenGiant avatar StephenGiant commented on June 20, 2024

我试了下 所有的硬编码写法都不行,只能@string

from tucao.

StephenGiant avatar StephenGiant commented on June 20, 2024

我试过了你的环境变量方式 现在报的是另一个错 我还是把中文替换成string了 毕竟博主用到中文混搭接口数据的地方没几个 改起来也不是很大工作量
@DerekDick

from tucao.

weiweiForAndroid avatar weiweiForAndroid commented on June 20, 2024

@DerekDick 怎么配置这个环境变量呢?

from tucao.

weiweiForAndroid avatar weiweiForAndroid commented on June 20, 2024

@StephenGiant 知道怎么配置环境变量么?

from tucao.

WinDerek avatar WinDerek commented on June 20, 2024

@weiweiForAndroid 配置环境变量的方法是通用的,这个百度一下吧

from tucao.

weiweiForAndroid avatar weiweiForAndroid commented on June 20, 2024

@DerekDick 配置好了,运行的时候提示 Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8

from tucao.

WinDerek avatar WinDerek commented on June 20, 2024

@weiweiForAndroid 这说明你环境变量配置成功了,忽略就行了

from tucao.

weiweiForAndroid avatar weiweiForAndroid commented on June 20, 2024

@DerekDick 好的 ,多谢。

from tucao.

Everglowzz avatar Everglowzz commented on June 20, 2024

JAVA_TOOL_OPTIONS

环境变量 俩个= 啥意思

from tucao.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.