如何允许硬编码字符串并停止询问使用strings.xml

raz*_*zak 4 string android android-studio

我目前正在研究一个Android项目,我没有任何计划将其翻译成其他语言,所以我没有在strings.xml中保存字符串文字.然而,每当我硬编码字符串文字时,Android Studio都会抱怨,特别是在设置文本值时TextView.

在此输入图像描述

在此输入图像描述

在此输入图像描述

有没有办法禁用这些警告?

DZD*_*omi 10

你可以在以下位置编辑它设置 - >编辑 - >检查 - > Android Lint-> TextView国际化:

编辑

对于xml设置 - >编辑器 - >检查 - > Android Lint->硬编码文本:

XML


小智 5

添加

@SuppressLint("SetTextI18n")
Run Code Online (Sandbox Code Playgroud)

在您的功能之上。例子:

@SuppressLint("SetTextI18n")
private void updateEZWBMode2ConnectionStatus(){
    switch (IsConnected.checkMode2(mContext)){
        case IsConnected.USB_TETHERING:
            M2StatusTV.setText("Status: Connected");
            M2StatusTV.setTextColor(Color.argb(255,0,255,0));
            M2ReceiveTV.setVisibility(View.VISIBLE);
            startTestReceiverSafe(M2ReceiveTV);
            break;
        case IsConnected.USB_CONNECTED:
            M2StatusTV.setText("Status: No Tethering");
            M2StatusTV.setTextColor(Color.argb(255,255,51,51));
            M1ReceiveTV.setVisibility(View.GONE);
            M2ReceiveTV.setVisibility(View.GONE);
            stopTestReceiverSafe();
            break;
        case IsConnected.USB_NOTHING:
            M2StatusTV.setText("Status: No USB Connection");
            M2StatusTV.setTextColor(Color.argb(255,255,51,51));
            M1ReceiveTV.setVisibility(View.GONE);
            M2ReceiveTV.setVisibility(View.GONE);
            stopTestReceiverSafe();
            break;
    }
}
Run Code Online (Sandbox Code Playgroud)


Tre*_*art 5

我认为最好的方法是使用 gradle 文件,这将允许您全局抑制这些,而不必在 Android Studio 中执行此操作,因此您的设置也可以进入源代码管理,然后您就不会必须单独装饰要应用警告的每个方法。为此,请在您的 gradle 文件 lint 选项中禁用 SetTextI18n,如下所示:

android {
    lintOptions{
        disable 'SetTextI18n'
    }
}
Run Code Online (Sandbox Code Playgroud)

Gradle 同步,瞧,警告消失了。