为 Android TV 应用嵌入欢迎图片
Posted
技术标签:
【中文标题】为 Android TV 应用嵌入欢迎图片【英文标题】:Embedd welcome image for Android TV app 【发布时间】:2016-05-01 21:39:45 【问题描述】:我想添加一个欢迎图像(.jpg/.png),它会显示一两秒,然后显示主应用程序屏幕。 我怎样才能做到这一点? 我不希望用户点击或滑动或任何东西.. 只需一/两秒的欢迎图片。
PS: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_
android:layout_
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_
android:layout_
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_
android:layout_
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_
android:layout_
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
【讨论】:
嘿,此链接已过期,您可以分享新链接或代码,我遇到了同样的问题以上是关于为 Android TV 应用嵌入欢迎图片的主要内容,如果未能解决你的问题,请参考以下文章