xml+javaでUIを表示

Posted by kwmt on Sun, Aug 29, 2010

setting.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">
	<CheckBox
	android:id="@+id/checkbox_maponoff_id"
	android:text="@string/checkbox_maponoff"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content" />
</LinearLayout>

SettingActivity.java

public class SettingActivity extends Activity implements View.OnClickListener {
	private  CheckBox chkbox = null; //チェックボックス
	//初期化
	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		//setting.xmlで記述したレイアウトを表示
		setContentView(R.layout.setting);
		//setting.xmlで記述した部品を使用したい場合
		chkbox = (CheckBox)findViewById( R.id.checkbox_id); //setting.xmlで指定したidを取得
		chkbox.setChecked(true); //チェックボックスをチェックした状態で初期化する
	}
}
setContentView(R.layout.setting);

の”setting”はxmlファイルのファイル名

結果はこれ。

背景が白いのは、

AndroidManifest.xml

で、

<!-- アプリケーションの定義 -->
<application  android:theme="@android:style/Theme.Light" >

というように、android:themeにTheme.Lightを指定しているため。

ちなみに、Theme.Light以外にもたくさんある。

http://developer.android.com/intl/ja/reference/android/R.style.html



comments powered by Disqus