日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

安卓笔记之配置第一个程序

發(fā)布時間:2024/9/5 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 安卓笔记之配置第一个程序 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

配置一個簡單的程序

主要通過src

??????????????????????????? |-java

和?????? res

??????????????????????????? |-layout

??????????????????????????? ??? |-main.xml

以及??? ????|-values

??????????????????????????? ???????? |-strings.xml?? 來完成

第一個在strings.xml沒有參與的情況下通過ID搭配配置文件

???????? 在main.xml下配置textview和button

?????????????????? ??????? <TextView

??????? android:id="@+id/mytext"???? -->要調取的ID

??????? android:layout_width="fill_parent"? ----》寬度

??????? android:layout_height="wrap_content" ----》高度

?????? />

??? <Button

??????? android:id="@+id/mybut"??? -->按鈕ID

??????? android:layout_width="fill_parent"

??????? android:layout_height="wrap_content"

?? />

然后在java程序中來調取

??? public void onCreate(Bundle savedInstanceState) {

??????? super.onCreate(savedInstanceState);

??????? setContentView(R.layout.main);

??????? TextView text = (TextView) super.findViewById(R.id.mytext);//取得TextView組件

??????? text.setText(“中國人”);//設置顯示文字

??????? Button but= (Button) super.findViewById(R.id.mybut);//取得按鈕組件

??????? but.setText(“按我”);

??? }

第二種在strings參與的情況下

??? 一時strings參與xml

??? <TextView

??????? android:id="@+id/mytext"???? -->要調取的ID

??????? android:layout_width="fill_parent"? ----》寬度

??????? android:layout_height="wrap_content" ----》高度

??????? android:text="@strings/text" -->要展示的文本 />

??? <Button

??????? android:id="@+id/mybut"??? -->按鈕ID

??????? android:layout_width="fill_parent"

??????? android:layout_height="wrap_content"

??????? android:text="@strings/msg" />

?

??? public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

??????? setContentView(R.layout.main);

??????? //TextView text = (TextView) super.findViewById(R.id.mytext);//取得TextView組件

??????? //text.setText(“中國人”);//設置顯示文字

??????? //Button but= (Button) super.findViewById(R.id.mybut);//取得按鈕組件

??????? //but.setText(“按我”);

??? }

??? 二是strings參與java

??? public void onCreate(Bundle savedInstanceState) {

??????? super.onCreate(savedInstanceState);

??????? setContentView(R.layout.main);

??????? TextView text = (TextView) super.findViewById(R.id.mytext);//取得TextView組件

??????? text.setText(R.string.text);//設置顯示文字

??????? Button but= (Button) super.findViewById(R.id.mybut);//取得按鈕組件

??????? but.setText(R.string.msg);

??? }

?

這兩種情況都要在strings中添加

<resources>

?

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

??? <string name="app_name">Zh</string>

??? <string name="text">中國人</string>

??? <string name="msg">按我</string>

?

</resources>

?

第三種情況

通過程序動態(tài)生成

?

? public void onCreate(Bundle savedInstanceState) {

??????? super.onCreate(savedInstanceState);

??????? LinearLayout layout = new LinearLayout(this);

??????? TextView text = new TextView(this);

??????? text.setText(super.getString(R.string.text));//通過strings.xml文件設置文字

??????? Button but = new Button(this);//定義按鈕

??????? but.setText(super.getString(R.string.msg));//配置組件文字

??????? layout.addView(text);//向布局管理器之中增加文本組件

??????? layout.addView(but);//想布局管理器之中增加按鈕組件

??????? super.setContentView(layout);//設置要使用的布局管理器

??? }

轉載于:https://www.cnblogs.com/kakaxi/archive/2011/11/09/2243096.html

總結

以上是生活随笔為你收集整理的安卓笔记之配置第一个程序的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。