1.令图片成为Activity的背景(填充整个屏幕)并且隐藏掉APP的项目标题栏
在values文件夹中的 styles.xml中添加一个样式
</
style>
<!--无标题栏样式-->
<
style name="AppTheme.NoActionBar">
<
item name="windowActionBar">false</
item>
<
item name="windowNoTitle">true</
item>
</
style>
然后在需要取消APP项目标题栏的Activity中添加该样式,具体做法是在
manifest文件的activity注册中写上
<
activity
android:name=".MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<
intent-filter>
<
action android:name="android.intent.action.MAIN" />
<
category android:name="android.intent.category.LAUNCHER" />
</
intent-filter>
</
activity>
顺便说明一下这段代码是确定项目的启动 activity 的代码,如果启动的时候无法找到启动的activity,那么就是没有这段代码
activity绑定的布局文件中确定背景图
<
LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/splash"></
LinearLayout>
2.activity的跳转
在MainActivity.Class中,先添加控件,如Button,通过findViewById()绑定控件,为控件添加点击监听,写跳转函数
public class MainActivity
extends AppCompatActivity {
private Button
btnLogin;
private Button
btnRegister;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.
activity_main);
btnLogin = (Button)findViewById(R.id.
btnLogin);
btnRegister = (Button)findViewById(R.id.
btnRegister);
btnLogin.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.
makeText(MainActivity.
this,
"你点击了登陆按钮",Toast.
LENGTH_LONG).show();
JumpLoginActivity();
}
});
btnRegister = (Button)findViewById(R.id.
btnRegister);
btnRegister.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.
makeText(MainActivity.
this,
"你点击了注册按钮",Toast.
LENGTH_LONG).show();
JumpRegisterActivity();
}
});
}
private void JumpRegisterActivity() {
Intent intent =
new Intent(MainActivity.
this,RegisterActivity.
class);
startActivity(intent);
}
private void JumpLoginActivity() {
Intent intent =
new Intent(MainActivity.
this,LoginActivity.
class);
startActivity(intent);
}
3.Toast 的写法
Toast.
makeText(MainActivity.
this,
"你点击了注册按钮",Toast.
LENGTH_LONG).show();