• <tfoot id='CT3BZ'></tfoot>

    1. <small id='CT3BZ'></small><noframes id='CT3BZ'>

      <i id='CT3BZ'><tr id='CT3BZ'><dt id='CT3BZ'><q id='CT3BZ'><span id='CT3BZ'><b id='CT3BZ'><form id='CT3BZ'><ins id='CT3BZ'></ins><ul id='CT3BZ'></ul><sub id='CT3BZ'></sub></form><legend id='CT3BZ'></legend><bdo id='CT3BZ'><pre id='CT3BZ'><center id='CT3BZ'></center></pre></bdo></b><th id='CT3BZ'></th></span></q></dt></tr></i><div id='CT3BZ'><tfoot id='CT3BZ'></tfoot><dl id='CT3BZ'><fieldset id='CT3BZ'></fieldset></dl></div>

    2. <legend id='CT3BZ'><style id='CT3BZ'><dir id='CT3BZ'><q id='CT3BZ'></q></dir></style></legend>
        • <bdo id='CT3BZ'></bdo><ul id='CT3BZ'></ul>

        硬编码字符串“第三行",应使用@string 资源

        hardcoded string quot;row threequot;, should use @string resource(硬编码字符串“第三行,应使用@string 资源)

        <i id='gVoTy'><tr id='gVoTy'><dt id='gVoTy'><q id='gVoTy'><span id='gVoTy'><b id='gVoTy'><form id='gVoTy'><ins id='gVoTy'></ins><ul id='gVoTy'></ul><sub id='gVoTy'></sub></form><legend id='gVoTy'></legend><bdo id='gVoTy'><pre id='gVoTy'><center id='gVoTy'></center></pre></bdo></b><th id='gVoTy'></th></span></q></dt></tr></i><div id='gVoTy'><tfoot id='gVoTy'></tfoot><dl id='gVoTy'><fieldset id='gVoTy'></fieldset></dl></div>

        <small id='gVoTy'></small><noframes id='gVoTy'>

          <legend id='gVoTy'><style id='gVoTy'><dir id='gVoTy'><q id='gVoTy'></q></dir></style></legend>

            <tbody id='gVoTy'></tbody>
              • <tfoot id='gVoTy'></tfoot>
                • <bdo id='gVoTy'></bdo><ul id='gVoTy'></ul>
                  本文介绍了硬编码字符串“第三行",应使用@string 资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是一名初学者 android 开发人员,我试图在 eclipse 中运行这个线性布局:

                      <?xml version="1.0" encoding="utf-8"?>
                  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                      android:orientation="vertical"
                      android:layout_width="fill_parent"
                      android:layout_height="fill_parent">
                  
                    <LinearLayout
                        android:orientation="horizontal"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:layout_weight="1">
                        <TextView
                            android:text="red"
                            android:gravity="center_horizontal"
                            android:background="#aa0000"
                            android:layout_width="wrap_content"
                            android:layout_height="fill_parent"
                            android:layout_weight="1"/>
                        <TextView
                            android:text="green"
                            android:gravity="center_horizontal"
                            android:background="#00aa00"
                            android:layout_width="wrap_content"
                            android:layout_height="fill_parent"
                            android:layout_weight="1"/>
                        <TextView
                            android:text="blue"
                            android:gravity="center_horizontal"
                            android:background="#0000aa"
                            android:layout_width="wrap_content"
                            android:layout_height="fill_parent"
                            android:layout_weight="1"/>
                        <TextView
                            android:text="yellow"
                            android:gravity="center_horizontal"
                            android:background="#aaaa00"
                            android:layout_width="wrap_content"
                            android:layout_height="fill_parent"
                            android:layout_weight="1"/>
                    </LinearLayout>
                  
                    <LinearLayout
                      android:orientation="vertical"
                      android:layout_width="fill_parent"
                      android:layout_height="fill_parent"
                      android:layout_weight="1">
                      <TextView
                          android:text="row one"
                          android:textSize="15pt"
                          android:layout_width="fill_parent"
                          android:layout_height="wrap_content"
                          android:layout_weight="1"/>
                      <TextView
                          android:text="row two"
                          android:textSize="15pt"
                          android:layout_width="fill_parent"
                          android:layout_height="wrap_content"
                          android:layout_weight="1"/>
                      <TextView
                          android:text="row three"
                          android:textSize="15pt"
                          android:layout_width="fill_parent"
                          android:layout_height="wrap_content"
                          android:layout_weight="1"/>
                      <TextView
                          android:text="row four"
                          android:textSize="15pt"
                          android:layout_width="fill_parent"
                          android:layout_height="wrap_content"
                          android:layout_weight="1"/>
                    </LinearLayout>
                  
                  </LinearLayout>
                  

                  而且,我注意到了:
                  1) android:text="Yellow"
                  下的黄线2) android:text="row 四"
                  下的黄线三角警告说 [I18N] Hardcoded string "Yellow", should use @string resource "其余的警告也一样.有什么建议吗?

                  And, I noticed :
                  1) yellow line under android:text="Yellow"
                  2) yellow line under android:text="row four"
                  the Triangle warn says [I18N] Hardcoded string "Yellow", should use @string resource " and same for the rest of the warnings.Any suggestion?

                  推荐答案

                  将字符串硬编码到布局文件中并不是一个好习惯.您应该将它们添加到字符串资源文件中,然后从您的布局中引用它们.

                  It is not good practice to hard code strings into your layout files. You should add them to a string resource file and then reference them from your layout.

                  这允许您通过编辑您的 strings.xml 文件同时更新所有布局中每个出现的单词Yellow".

                  This allows you to update every occurrence of the word "Yellow" in all layouts at the same time by just editing your strings.xml file.

                  它对于支持多种语言也非常有用,因为单独的 strings.xml 文件可用于每种支持的语言.

                  It is also extremely useful for supporting multiple languages as a separate strings.xml file can be used for each supported language.

                  示例:保存在 res/values/strings.xml 的 XML 文件:

                  example: XML file saved at res/values/strings.xml:

                  <?xml version="1.0" encoding="utf-8"?>
                  <resources>
                      <string name="yellow">Yellow</string>
                  </resources>
                  

                  此布局 XML 将字符串应用于视图:

                  This layout XML applies a string to a View:

                  <TextView android:layout_width="fill_parent"
                            android:layout_height="wrap_content"
                            android:text="@string/yellow" />
                  

                  类似的颜色应该存储在 colors.xml 中,然后使用 @color/color_name 引用

                  Similarly colors should be stored in colors.xml and then referenced by using @color/color_name

                  <?xml version="1.0" encoding="utf-8"?>
                  <resources>
                      <color name="Black">#000000</color>
                  </resources>
                  

                  这篇关于硬编码字符串“第三行",应使用@string 资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)
                  cocos2d-android: how to display score(cocos2d-android:如何显示分数)
                  Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
                  SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
                  Android file copy(安卓文件拷贝)
                  Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)

                • <tfoot id='gaRlN'></tfoot>
                  <legend id='gaRlN'><style id='gaRlN'><dir id='gaRlN'><q id='gaRlN'></q></dir></style></legend>

                  <small id='gaRlN'></small><noframes id='gaRlN'>

                      <bdo id='gaRlN'></bdo><ul id='gaRlN'></ul>

                            <tbody id='gaRlN'></tbody>

                          • <i id='gaRlN'><tr id='gaRlN'><dt id='gaRlN'><q id='gaRlN'><span id='gaRlN'><b id='gaRlN'><form id='gaRlN'><ins id='gaRlN'></ins><ul id='gaRlN'></ul><sub id='gaRlN'></sub></form><legend id='gaRlN'></legend><bdo id='gaRlN'><pre id='gaRlN'><center id='gaRlN'></center></pre></bdo></b><th id='gaRlN'></th></span></q></dt></tr></i><div id='gaRlN'><tfoot id='gaRlN'></tfoot><dl id='gaRlN'><fieldset id='gaRlN'></fieldset></dl></div>