/*MainActivity.java*/
package com.example.my_ui;
import android.app.Activity;
import android.graphics.Color;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.TypedValue;
import android.widget.FrameLayout;
import android.widget.TextView;
public class MainActivity extends Activity {
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FrameLayout frameLayout=new FrameLayout(this);//创建帧布局管理器
frameLayout.setBackground(this.getResources().getDrawable(R.drawable.welcome));//设置背景
setContentView(frameLayout);//设置在Activity中显示frameLayout
TextView textView=new TextView(this);
textView.setText("在Java中显示UI界面");//设置显示的文字
/**
* setTextSize(TypedValue.COMPLEX_UNIT_PX,22); //22PX
setTextSize(TypedValue.COMPLEX_UNIT_SP,22); //22SP
setTextSize(TypedValue.COMPLEX_UNIT_DIP,22);//22DIP
*
*/
textView.setTextSize(TypedValue.COMPLEX_UNIT_PT,10);
textView.setTextColor(Color.parseColor("#ff0000"));//#ff0000:红;#FCCC2C:橙;#FDFD00:黄;#00ff00:绿;#01FFFF:青;#0000ff:蓝;#A700FF:紫
//textView.setTextColor(Color.RED);
frameLayout.addView(textView);//将textView添加到布局管理器中
}
}