package com.example.q9722.gaicuo;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.WindowManager;
public class SplashActivity extends AppCompatActivity implements Runnable{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash);
new Thread(this).start();
}
@Override
public void run() {
SharedPreferences preferences = getSharedPreferences("app_splash",MODE_PRIVATE);
if(preferences.getBoolean("splash",false)) {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("splash",true);
editor.commit();
}else {
Intent intent = new Intent();
intent.setClass(SplashActivity.this,MainActivity.class);
startActivity(intent);
finish();
}
}
}
你是想全屏 横屏显示图片的欢迎页面是吧 我最近也在做
1、布局 把图片全屏显示
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/relative"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/welcomepic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:scaleType="fitXY"
android:src="@mipmap/welcome" />
</RelativeLayout>
2、设置全屏 还有横屏
在setContentView之前设置:
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
在androidmanifest.xml设置横屏
android:screenOrientation="portrait"
有什么问题 可以私信我 望采纳
ps:请问怎么设置默认横屏显示
我也觉得的确真是跟java代码差不多呢
你贴的这个跟图片有关系?
在模拟器里面可以显示吗??
图片是在那里啊?在 activity_splash?
可以先删除部分代码调试一下.
代码不涉及图片显示问题
换一张图片,或重新生成JPEG图片。
如果还是不能正常显示,建议在设置完VISIBLE后,调用如下方法: