読者です 読者をやめる 読者になる 読者になる

矩形を表示させる

package com.example.xxx;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Canvas;
import android.view.Menu;
import android.widget.*;
import android.content.*;
import android.graphics.*;
import android.view.*;

public class MainActivity extends Activity {
	
	public TextView textView;
	public LinearLayout layout;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        LinearLayout linearLayout = new LinearLayout(this);
        setContentView(linearLayout);
        
        /*
        textView = new TextView(this);
        textView.setText("toshinari");
        linearLayout.addView(textView);
        */
        
        linearLayout.addView(new MyView(this));
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    class MyView extends View{
    	public MyView(Context context){
    		super(context);
    	}
    	
    	@Override
    	protected void onDraw(Canvas canvas){
    		Paint paint = new Paint();
    		paint.setColor(Color.argb(255, 255, 0, 0));
    		canvas.drawRect(0, 0, 100, 100, paint);
    	}
    }
}