java를 이용하는 방법

package com.sample;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.LinearLayout;

public class sample extends Activity {
    /** Called when the activity is first created. */
 
    private LinearLayout mLayout; 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        //배경화면을 흰색으로 채운다.
        mLayout = (LinearLayout) findViewById(R.id.mLayout);
        mLayout.setBackgroundColor(Color.rgb(255,255,255));
        
    }
}


XML을 이용하는 방법


main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mLayout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/bg"
>
.
.
.
</LinearLayout>

strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">샘플</string>
    <color name="bg">#FFFFFF</color>
</resources>

저작자 표시
신고
Posted by @shstarkr


티스토리 툴바