[启动画面]如何全屏显示图像?

时间:2011-08-02 20:48:26

标签: android

我想在我的应用程序中制作启动画面,因为我需要知道如何在全屏显示图像。这可以通过XML或Java代码制作吗?如何? 现在我刚刚做了这个:

public class SplashScreen extends Activity {

    private static final int STOPSPLASH = 0;

    private static final long SPLASHTIME = 5000;



    private Handler splashHandler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
    switch (msg.what) {
    case STOPSPLASH:
    //remove SplashScreen from view
    Intent intent = new Intent(SplashScreen.this, jetpack.class);
    startActivity(intent);
    break;
    }
    super.handleMessage(msg);
    }
    };



    @Override

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash_screen);
    Message msg = new Message();
    msg.what = STOPSPLASH;
    splashHandler.sendMessageDelayed(msg, SPLASHTIME);
    }
    }

这个splash_screen.xml怎么样? 谢谢你的帮助。

5 个答案:

答案 0 :(得分:27)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" 
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:src="@drawable/image" />
</LinearLayout>

并在代码中添加

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

在setContentView(R.layout.splash_screen)之前;

答案 1 :(得分:26)

显示全屏启动活动的最佳方法是将此行放在活动代码

下的清单中

<强>机器人:主题= “@机器人:风格/ Theme.Light.NoTitleBar.Fullscreen”

您也可以使用其他主题

<强> Theme.Black.NoTitleBar.Fullscreen
Theme.NoTitleBar.Fullscreen

<activity
        android:name="com.example.SplashActivity"
        android:label="@string/app_name" 
        android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

最新Api Lollipop及以上

<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>

为splash活动定义此主题并在清单

中提供

<强>机器人:主题= “@风格/ Theme.AppCompat.Light.NoActionBar.FullScreen”

答案 2 :(得分:1)

如果R.layout.splash_screen包含高度和宽度设置为fill_parent或match_parent(取决于版本)的图像。它将填满屏幕

答案 3 :(得分:0)

 <style name="FullScreen" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
</style>

答案 4 :(得分:0)

enter image description here


仅使用 super.onCreatesetConntentView

代码:

/** Hiding Title bar of this activity screen */
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
/** Making this activity, full screen */
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash);