안드 5-3
package com.example.secondnonxml;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import org.w3c.dom.Text;
public class MainActivity extends AppCompatActivity {
EditText edit;
Button btn;
TextView tex;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
LinearLayout.LayoutParams params= new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
//리니어 레이아웃 변수의 선언
LinearLayout baseLayout= new LinearLayout(this);
baseLayout.setOrientation(LinearLayout.VERTICAL);
baseLayout.setBackgroundColor(Color.rgb(0, 255, 0));
setContentView(baseLayout, params);
edit = new EditText(this);
btn= new Button(this);
tex=new TextView(this);
edit.setHint("입력하시오");
baseLayout.addView(edit);
btn.setText("버튼입니다");
btn.setBackgroundColor(Color.rgb(0, 122, 0));
baseLayout.addView(btn);
tex.setTextSize(30);
tex.setTextColor(Color.MAGENTA);
baseLayout.addView(tex);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String sentence;
sentence= edit.getText().toString();
tex.setText(sentence);
}
});
}
}
/////////////////////////////
mainactivity 없이 오직 java로만 코드짜기