欢迎来到天天文库
浏览记录
ID:14012914
大小:3.64 MB
页数:223页
时间:2018-07-25
《android基础教程--csdn 魏竹林》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、显示文字签在Android初级教程(五)我们写了HelloAndroid之后,一直觉得没有写半行代码对不起自己,所以本节,我们将在HelloAndroid基础之上,进行与TextView文字标签的第一次接触.在此例中,将会在Layout中创建TextView对象,并学会定义res/values/string.xml里的字符串常数,最后通过TextView的setText方法,在预加载程序之初,更改TextView文字. 首先看一下运行结果如下图: 首先"欢迎来到魏祝林的博客"这几个字是从什么地方来
2、的呢,我们是在res->values->string.xml里面加了如下一句(黑体): HelloWorld,HelloAndroid! HelloAndroid 欢迎来到魏祝林的博客3、ces> 而加载"欢迎来到魏祝林的博客"是在main.xml(定义手机布局界面的)里加入的,如下面代码,其中我们闺将@string/hello改成了@string/textView_text. 4、ut_width="fill_parent" android:layout_height="fill_parent" > 这样我们运行HelloAndroid.java时,手机画面里将显示"欢迎来到魏祝林的博5、客"的欢迎界面,貌似我们又是没有写代码,只是在.xml加了一两行搞定,对习惯了编程的同学,感觉有点不适应.其实在HelloAndroid.java写代码也可以完全达到一样的效果. 在这里我们首先将main.xml回归到原样在原样的基础上加上一行见下方(黑体行)这里ID是为了在Java类里,找到TextView对象,并且可以控制它: 6、d.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" >7、 android:text="@string/hello" /> 在主程序HelloAndroid.java里代码如下: packagecom.android.test;importandroid.app.Activity;importandroid.os.Bundle;importandroid.widget.TextView;publicclassHelloAndroidextendsActivity{ privateTextViewmyTextVie8、w; publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); //载入main.xmlLayout,此时myTextView:text为hello setContentView(R.layout.main); //使用findViewById函数,利用ID找到该TextView对象 m
3、ces> 而加载"欢迎来到魏祝林的博客"是在main.xml(定义手机布局界面的)里加入的,如下面代码,其中我们闺将@string/hello改成了@string/textView_text. 4、ut_width="fill_parent" android:layout_height="fill_parent" > 这样我们运行HelloAndroid.java时,手机画面里将显示"欢迎来到魏祝林的博5、客"的欢迎界面,貌似我们又是没有写代码,只是在.xml加了一两行搞定,对习惯了编程的同学,感觉有点不适应.其实在HelloAndroid.java写代码也可以完全达到一样的效果. 在这里我们首先将main.xml回归到原样在原样的基础上加上一行见下方(黑体行)这里ID是为了在Java类里,找到TextView对象,并且可以控制它: 6、d.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" >7、 android:text="@string/hello" /> 在主程序HelloAndroid.java里代码如下: packagecom.android.test;importandroid.app.Activity;importandroid.os.Bundle;importandroid.widget.TextView;publicclassHelloAndroidextendsActivity{ privateTextViewmyTextVie8、w; publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); //载入main.xmlLayout,此时myTextView:text为hello setContentView(R.layout.main); //使用findViewById函数,利用ID找到该TextView对象 m
4、ut_width="fill_parent" android:layout_height="fill_parent" > 这样我们运行HelloAndroid.java时,手机画面里将显示"欢迎来到魏祝林的博
5、客"的欢迎界面,貌似我们又是没有写代码,只是在.xml加了一两行搞定,对习惯了编程的同学,感觉有点不适应.其实在HelloAndroid.java写代码也可以完全达到一样的效果. 在这里我们首先将main.xml回归到原样在原样的基础上加上一行见下方(黑体行)这里ID是为了在Java类里,找到TextView对象,并且可以控制它: 6、d.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" >7、 android:text="@string/hello" /> 在主程序HelloAndroid.java里代码如下: packagecom.android.test;importandroid.app.Activity;importandroid.os.Bundle;importandroid.widget.TextView;publicclassHelloAndroidextendsActivity{ privateTextViewmyTextVie8、w; publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); //载入main.xmlLayout,此时myTextView:text为hello setContentView(R.layout.main); //使用findViewById函数,利用ID找到该TextView对象 m
6、d.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" >7、 android:text="@string/hello" /> 在主程序HelloAndroid.java里代码如下: packagecom.android.test;importandroid.app.Activity;importandroid.os.Bundle;importandroid.widget.TextView;publicclassHelloAndroidextendsActivity{ privateTextViewmyTextVie8、w; publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); //载入main.xmlLayout,此时myTextView:text为hello setContentView(R.layout.main); //使用findViewById函数,利用ID找到该TextView对象 m
7、 android:text="@string/hello" /> 在主程序HelloAndroid.java里代码如下: packagecom.android.test;importandroid.app.Activity;importandroid.os.Bundle;importandroid.widget.TextView;publicclassHelloAndroidextendsActivity{ privateTextViewmyTextVie
8、w; publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); //载入main.xmlLayout,此时myTextView:text为hello setContentView(R.layout.main); //使用findViewById函数,利用ID找到该TextView对象 m
此文档下载收益归作者所有