Android学习笔记字符串资源

在新建好的Android项目里res目录下有个字符串资源文件

在xml文件中引用字符串资源

string.xml

<resources>
    <string name="motto">未闻花名,但识花香。再见花识类已千行</string>
</resources>

activity_main.xml

<TextView
        android:id="@+id/motto"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/motto"/>

通过Java引用资源文件

MainActivity.java

        TextView tv_motto = findViewById(R.id.motto);
        tv_motto.setText(getResources().getString(R.string.motto));
posted @ 2020-05-04 22:25  千雨千寻  阅读(129)  评论(0编辑  收藏  举报