從零開(kāi)始學(xué)android小示例程序
更新時(shí)間:2014年02月08日 14:54:14 作者:
這篇文章主要介紹了一個(gè)學(xué)習(xí)android開(kāi)發(fā)的小示例程序,需要的朋友可以參考下
![]() |
布局文件
復(fù)制代碼 代碼如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/showWord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/GreenBtn"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/BlueBtn"
android:layout_marginTop="17dp"
android:text="@string/ShowWordText"
android:textStyle="bold" />
<Button
android:id="@+id/GreenBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/showWord"
android:layout_marginLeft="22dp"
android:layout_marginTop="28dp"
android:gravity="left|center_vertical|center_horizontal"
android:text="@string/GreenBtnText" />
<Button
android:id="@+id/BlueBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/YellowBtn"
android:layout_alignBottom="@+id/YellowBtn"
android:layout_toRightOf="@+id/YellowBtn"
android:gravity="left|center_vertical|center_horizontal"
android:text="@string/BlueBtnText" />
<Button
android:id="@+id/YellowBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/GreenBtn"
android:layout_alignBottom="@+id/GreenBtn"
android:layout_toRightOf="@+id/GreenBtn"
android:gravity="left|center_vertical|center_horizontal"
android:text="@string/YellowBtnText" />
</RelativeLayout>
復(fù)制代碼 代碼如下:
package com.example.demo1;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.app.Activity;
import android.graphics.Color;
public class MainActivity extends Activity implements OnClickListener{
TextView tv_show=null;
Button greenBtn=null;
Button blueBtn=null;
Button yellowBtn=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv_show=(TextView)findViewById(R.id.showWord);
greenBtn=(Button)findViewById(R.id.GreenBtn);
blueBtn=(Button)findViewById(R.id.BlueBtn);
yellowBtn=(Button)findViewById(R.id.YellowBtn);
greenBtn.setOnClickListener(this);
blueBtn.setOnClickListener(this);
yellowBtn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.GreenBtn:
tv_show.setTextColor(Color.GREEN);
break;
case R.id.BlueBtn:
tv_show.setTextColor(Color.BLUE);
break;
case R.id.YellowBtn:
tv_show.setTextColor(Color.YELLOW);
break;
default:
break;
}
}
}
您可能感興趣的文章:
- android教程之hockeyapp捕獲異常示例
- android開(kāi)發(fā)教程之實(shí)現(xiàn)listview下拉刷新和上拉刷新效果
- android配合viewpager實(shí)現(xiàn)可滑動(dòng)的標(biāo)簽欄示例分享
- android顯示TextView文字的倒影效果實(shí)現(xiàn)代碼
- android教程之使用popupwindow創(chuàng)建菜單示例
- android教程之使用asynctask在后臺(tái)運(yùn)行耗時(shí)任務(wù)
- android教程之service使用方法示例詳解
- android教程之textview解析帶圖片的html示例
- Android中的Looper對(duì)象詳細(xì)介紹
- Android ImageButton自定義按鈕的按下效果的代碼實(shí)現(xiàn)方法分享
- android開(kāi)發(fā)教程之系統(tǒng)資源的使用方法 android資源文件
- android開(kāi)發(fā)教程之使用listview顯示qq聯(lián)系人列表
- android開(kāi)發(fā)教程之listview使用方法
- 從零開(kāi)始學(xué)android實(shí)現(xiàn)計(jì)算器功能示例分享(計(jì)算器源碼)
- Android中實(shí)現(xiàn)可滑動(dòng)的Tab的3種方式
- Android創(chuàng)建服務(wù)之started service詳細(xì)介紹
- android教程之intent的action屬性使用示例(intent發(fā)短信)
- android教程之把自己的應(yīng)用加入到系統(tǒng)分享中
相關(guān)文章
Android自定義密碼輸入框和數(shù)字鍵盤(pán)
這篇文章主要為大家詳細(xì)介紹了Android自定義密碼輸入框和數(shù)字鍵盤(pán)的相關(guān)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06
TextView實(shí)現(xiàn)圖文混合編排的方法
這篇文章主要為大家詳細(xì)介紹了TextView實(shí)現(xiàn)圖文混合編排的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08
Android實(shí)現(xiàn)銀行卡號(hào)掃描識(shí)別功能
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)銀行卡號(hào)掃描識(shí)別功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-09-09
教你3分鐘了解Android 簡(jiǎn)易時(shí)間軸的實(shí)現(xiàn)方法
本篇文章主要介紹了教你3分鐘了解Android 簡(jiǎn)易時(shí)間軸的實(shí)現(xiàn)方法,具有一定的參考價(jià)值,有興趣的可以了解一下2017-07-07
Android TextView控件文字添加下劃線的實(shí)現(xiàn)方法
下面小編就為大家?guī)?lái)一篇Android TextView控件文字添加下劃線的實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-09-09
Android 實(shí)現(xiàn)監(jiān)聽(tīng)的四種方法詳解實(shí)例代碼
這篇文章主要介紹了Android 實(shí)現(xiàn)監(jiān)聽(tīng)的方法詳解實(shí)例代碼的相關(guān)資料,這里整理了四種方法,需要的朋友可以參考下2016-10-10
flutter實(shí)現(xiàn)發(fā)送驗(yàn)證碼功能
這篇文章主要為大家詳細(xì)介紹了flutter發(fā)送驗(yàn)證碼功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-07-07


