pertama buka eclipse terlebih dahulu lalu buat projectnya.
'File>New>Android Application Project' kemudian tentukan spesifikasinya.
saya menggunakan spesifikasi seperti ini:
kemudian kita buat tampilan seperti ini:
untuk membuat tampilan seperti diatas masukan coding ini ke main.xml:
===========================================================
<?xml version="1.0"
encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/txtChange"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#AA0000"
android:textSize="16sp"
android:text="I am red"
/>
<Button
android:id="@+id/btnRed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change to Red"/>
<Button
android:id="@+id/btnBlue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change to Blue"/>
<Button
android:id="@+id/btnGreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change to Green"/>
</LinearLayout>
kemudian masukan coding ini ke main.java :
===================================================
package com.example.merubahwarnatulisan;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Main extends Activity {
@Override
protected void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView
txtChange = (TextView)findViewById(R.id.txtChange);
Button btnRed
= (Button)findViewById(R.id.btnRed);
Button btnBlue
= (Button)findViewById(R.id.btnBlue);
Button
btnGreen = (Button)findViewById(R.id.btnGreen);
btnRed.setOnClickListener(new View.OnClickListener() {
public
void onClick(View v) {
//
TODO Auto-generated method stub
txtChange.setTextColor(Color.parseColor("#AA0000"));
txtChange.setText("I am red");
}
});
btnBlue.setOnClickListener(new View.OnClickListener() {
public
void onClick(View v) {
//
TODO Auto-generated method stub
txtChange.setTextColor(Color.parseColor("#0000AA"));
txtChange.setText("I
am blue");
}
});
btnGreen.setOnClickListener(new View.OnClickListener() {
public
void onClick(View v) {
//
TODO Auto-generated method stub
txtChange.setTextColor(Color.parseColor("#00ff00"));
txtChange.setText("I am green");
}
});
}
}
======================================================jika sudah run di main.xml maka hasilnya akan seperti gambar di bawah ini :
sekian postingan dari saya semoga bermanfaat untuk teman-teman,tunggu postingan selanjutnya dari saya yah..........





Tidak ada komentar:
Posting Komentar