首先打开ADT程序创建
创建文件如图:
命名Day01
在res-layout中打开activity_main文件,
下面第一个文件为视图,第二个对视图进行编辑
点击第二个,我们要放一个背景图片,插入<LinearLayout>线性布局,并对其定义属性,具体代码如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ic_launcher"
tools:context=".MainActivity" >
</LinearLayout>
此代码演示将用背景图片将线性布局填充完整,按题目要求走隐藏状态栏和标题并停止界面三秒,打开src对包com.exeample.day01中的Java文件MainActivity进行编辑
定义类MainActivity继承其父类Activity
对方法onCreate方法进行重写
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
按要求走在界面停止三秒,运用到线程的知识,
首先new一个Thread类,
1实现Runable接口,重写run方法
2创建Runable子类对象
3然后对界面进行跳转,Intent it = new Intent(A,B);A表示当前文件,B表示跳转界面
4调用Thread()对象的start()方法启动线程
代码演示如下
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try {
//将此代码进行调控
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//停止三秒后跳转
Intent it = new Intent(getApplicationContext(),
AppActivity.class);
startActivity(it);
}
});
thread.start();
}
隐藏状态栏和标题的方法为:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getActionBar().hide();
注意放入代码的位置
jdk小于11会报错。
整合以上三个代码就完成了对MainActivity的编辑
package com.example.day06;
import android.os.Build;
import android.os.Bundle;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.WindowManager;
public class MainActivity extends Activity {
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//隐藏状态栏
// getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
//隐藏标题栏
getActionBar().hide();
setContentView(R.layout.activity_main);
//开启一个线程(3秒自动跳转)
Thread t=new Thread(new Runnable() {
@Override
public void run() {
// 等待三秒
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//启动第二个页面
Intent it = new Intent(getApplicationContext(),
LoinActivity.class);
startActivity(it);
}
}) ;
t.start();
}
}
现在对第二个页面的Android页面进行编辑
在项目中新健Android的文件
通过<LinearLayout><TextView><EditText><CheckBox><RadioButtn>等控件对安卓哦安儿页面进行展示
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".LoinActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#293f47"