【问题标题】:Embedd welcome image for Android TV app为 Android TV 应用嵌入欢迎图片
【发布时间】:2016-05-01 21:39:45
【问题描述】:

我想添加一个欢迎图像(.jpg/.png),它会显示一两秒,然后显示主应用程序屏幕。 我怎样才能做到这一点? 我不希望用户点击或滑动或任何东西.. 只需一/两秒的欢迎图片。

PS:Android TV 应用

【问题讨论】:

  • 如何为安卓电视解决这个问题?

标签: android-layout android-tv


【解决方案1】:

很简单,我正在分享代码。您只需要创建启动器类别为 LEANBACK_LAUNCHER 的 Splash Activity。

  **SplashActivity.java**

    package com.example.ttnd.splashscreendemo;

    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.os.Handler;

    public class SplashActivity extends Activity {

        // Splash screen timer
        private static int SPLASH_TIME_OUT = 3000;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_splash);


            new Handler().postDelayed(new Runnable() {

                /*
                 * Showing splash screen with a timer. This will be useful when you
                 * want to show case your app logo / company
                 */

                @Override
                public void run() {
                    // This method will be executed once the timer is over
                    // Start your app main activity
                    Intent i = new Intent(SplashActivity.this, MainActivity.class);
                    startActivity(i);

                    // close this activity
                    finish();
                }
            }, SPLASH_TIME_OUT);
        }

    }




    **activity_splash.xml**

    <?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:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.example.ttnd.splashscreendemo.SplashActivity">


        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher"
            android:layout_centerInParent="true"
            />

    </RelativeLayout>


MainActivity.java

package com.example.ttnd.splashscreendemo;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}


activity_main.xml


<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.ttnd.splashscreendemo.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Here you are!"/>

</RelativeLayout>



manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.ttnd.splashscreendemo">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.Leanback">
        <activity android:name=".SplashActivity">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

        </activity>
        <activity android:name=".MainActivity"></activity>
    </application>

</manifest>

【讨论】:

    【解决方案2】:

    您可以查看 Android 开发人员的这篇文章。同样的方法适用于手机和电视。

    https://plus.google.com/+AndroidDevelopers/posts/Z1Wwainpjhd

    【讨论】:

    • 嘿,此链接已过期,您可以分享新链接或代码,我遇到了同样的问题
    猜你喜欢
    • 1970-01-01
    • 2020-06-15
    • 1970-01-01
    • 1970-01-01
    • 2021-04-28
    • 2021-10-09
    • 2020-05-18
    • 2021-02-15
    • 2021-06-16
    相关资源
    最近更新 更多