<TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" />
<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" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="39dp" android:text="TextView" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView1" android:layout_centerHorizontal="true" android:layout_marginTop="31dp" android:text="My TextView" /> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView1" android:layout_below="@+id/textView2" android:layout_marginTop="36dp" android:text="TextView" /> </RelativeLayout>
package com.myapp; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widget.TextView; import android.app.AlertDialog; import android.graphics.*; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final AlertDialog.Builder adb = new AlertDialog.Builder(this); // textView2 Event final TextView txt2 = (TextView) findViewById(R.id.textView2); txt2.setTextColor(Color.parseColor("#CCCCCC")); // Perform action on click txt2.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { AlertDialog ad = adb.create(); ad.setMessage("textView2 Event Click"); ad.show(); } }); // textView3 TextView txt3 = (TextView)findViewById(R.id.textView3); txt3.setText("Change Text on Runtime"); txt3.setTextColor(Color.RED); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท