Skip to content

Instantly share code, notes, and snippets.

@Pornpun
Last active September 19, 2015 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pornpun/12e2793dc99b30bfd32d to your computer and use it in GitHub Desktop.
Save Pornpun/12e2793dc99b30bfd32d to your computer and use it in GitHub Desktop.
TestApp
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView
android:id="@+id/tv_text"
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffff2455"/>
</RelativeLayout>
package com.mystou.testapp;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// ประกาศตัวแปรประเภท TextView
TextView textView;
// กำหนดค่าให้ตัวแปร = id tv_text
textView = (TextView) findViewById(R.id.tv_text);
// เปลียนข้อความ textView เป็น สวัสดี
textView.setText("สวัสดี");
// เปลียนสีพื้นหลังเป็นสีเขียว
textView.setBackgroundColor(Color.GREEN);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment