You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio中@string引用失效,控件显示原始字符串求助

Hey, I’ve dealt with this frustrating issue a few times—let’s walk through the most likely fixes that usually resolve it:

Troubleshooting @string Resources Not Rendering in Android
  • Double-check your strings.xml setup
    First, confirm your strings are properly defined in res/values/strings.xml (or the correct locale-specific subfolder if you’re localizing). Avoid special characters, spaces, or uppercase letters in resource names—stick to lowercase, numbers, and underscores. For example:

    <!-- This works -->
    <string name="app_name">myapp</string>
    <string name="action_sign_in">Sign In</string>
    

    A tiny typo here (like app_namee instead of app_name) will make Android fall back to showing the raw @string/ reference.

  • Clean and rebuild your project
    Build cache corruption is super common here. Head to Android Studio’s menu: Build > Clean Project, then Build > Rebuild Project. This forces the IDE to recompile all your resources from scratch, which often fixes stale or mislinked references.

  • Check for resource conflicts
    If you’re using third-party libraries or multiple modules, there might be a duplicate resource name (e.g., another library defines app_name too). To check this, right-click your res folder and select Open Resource Manager—look for entries marked with a warning icon. If you find a conflict, rename your string (like my_app_name) to avoid the clash.

  • Verify your references are 100% correct
    It sounds obvious, but make sure you didn’t accidentally hardcode the reference text. For example, android:text="@string/action_sign_in" is correct—but if you missed the @string/ part (or had a typo like @string/action_signin), it’ll show the raw text instead of the actual string value.

  • Check your build.gradle configuration
    Make sure your module’s build.gradle (or build.gradle.kts) is correctly pointing to your res folder. The sourceSets should look like this:

    android {
        sourceSets {
            main {
                res.srcDirs = ['src/main/res']
            }
        }
    }
    

    If this is misconfigured, Android won’t pick up your string resources at all.

  • Test on a different device/emulator
    Sometimes emulators hold onto cached resources that don’t update. Try running the app on a physical device or creating a brand new emulator to rule out this edge case.

Most of the time, one of these steps will fix the problem—start with cleaning the project and checking for typos, since those are the most frequent culprits!


内容的提问来源于stack exchange,提问作者Kaigo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:13:14