码迷,mamicode.com
首页 > 其他好文 > 详细

04项目的目录结构分析与资源引用

时间:2017-07-17 11:11:07      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:mat   cti   earth   oid   public   str   welcome   .text   blog   

普通字符串资源:

 技术分享

布局资源:

 技术分享

案例:

main.xml:

<TextView

        android:id="@+id/textView1"

        android:layout_width="match_parent"

        android:layout_height="240dp"

        android:text="加油吧!少年!"

        />

    <Button

        android:id="@+id/button1"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:text="@string/msg"

        android:onClick="test"

        />

R.java:

public final class R {

    public static final class attr {

    }

    public static final class drawable {

        public static final int ic_launcher=0x7f020000;

    }

    public static final class id {

        public static final int button1=0x7f050001;

        public static final int textView1=0x7f050000;

    }

    public static final class layout {

        public static final int main=0x7f030000;

    }

    public static final class string {

        public static final int app_name=0x7f040000;

        public static final int hello=0x7f040001;

        public static final int msg=0x7f040002;

    }

}

 

Strings.xml:

<resources>

    <string name="app_name">ONEAndroid</string>

    <string name="hello">Hello World, ONEAndroidActivity!</string>

    <string name="msg">welcome,weini!</string>

</resources>

 

ONEAndroidActivity.java:

public void test(View view){

     TextView textView1=(TextView) findViewById (R.id.textView1);

     textView1.setText("The greatest test of courage on earth is to bear defeat without losing heart\n世界上对勇气的最大考验是忍受失败而不丧失信心。");

     Toast.makeText(ONEAndroidActivity.this, "点击button",Toast.LENGTH_SHORT).show();

}

 

运行结果:

点击按钮前:技术分享

 

  点击按后:技术分享

 

中英文时候的选择:

 技术分享

技术分享

 

图示:

 技术分享

 

04项目的目录结构分析与资源引用

标签:mat   cti   earth   oid   public   str   welcome   .text   blog   

原文地址:http://www.cnblogs.com/cxm-weiniss/p/7193103.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!