ANDROID APP
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
96 บทที่ 4 ส่วนการติดต่อกับผู้ใช้งาน (User Interface)<br />
ชุดคำสั่งที่ 4.8 res/layout/main.xml<br />
<br />
<br />
<br />
<br />
<br />
ชุดคำสั่งที่ 4.9 res/values/strings.xml<br />
<br />
<br />
ChangeFont<br />
Rainbow Connection<br />
Press to change the font color<br />
<br />
แอคทิวิตี้ที่แสดงในชุดคำสั่งที่ 4.10 จะทำงานร่วมกับไฟล์ main.xml และเมื่อปุ่มถูกกด ฟัง<br />
ก์ชั่น OnClickListener จะกำหนดสีให้แก่ข้อความตามค่าอ้างอิงในตารางที่ 4.3 โดยสีที่จะใช้งาน<br />
สามารถประกาศไว้ในไฟล์ colors.xml ตามที่แสดงในชุดคำสั่งที่ 4.11 ได้เช่นกัน การกำหนดค่าของสี<br />
ไว้ในไฟล์ XML ภายนอกนั้น จะช่วยให้เราสามารถแก้ไขสีของข้อความได้ง่ายโดยไม่จำเป็นต้องแก้ไข<br />
การทำงานของแฮนด์เลอร์<br />
ชุดคำสั่งที่ 4.10 src/com/cookbook/change_font/ChangeFont.java<br />
package com.cookbook.change_font;<br />
import android.app.Activity;<br />
import android.os.Bundle;<br />
import android.view.View;<br />
import android.widget.Button;<br />
import android.widget.TextView;<br />
public class ChangeFont extends Activity {<br />
TextView tv;<br />
private int color_vals[]={R.color.start, R.color.mid, R.color.last};<br />
int idx=0;