View 淡出启动屏幕而不使用意图

View 淡出启动屏幕而不使用意图,view,webview,splash-screen,View,Webview,Splash Screen,因此,我最近在我的应用程序中添加了一个启动屏幕,没有使用任何其他活动,正如我大部分搜索发现的那样 一切都正常工作,但我的目标是让它在加载视图时淡出,最好是在加载视图之后,因为它是一个webview 在不使用单独的活动和意图的情况下,实现闪屏淡出动画的最佳方法是什么 下面是我主要活动中的工作代码 package com.chris.myapp; import android.content.Intent; import android.net.Uri; import android.os.Bun

因此,我最近在我的应用程序中添加了一个启动屏幕,没有使用任何其他活动,正如我大部分搜索发现的那样

一切都正常工作,但我的目标是让它在加载视图时淡出,最好是在加载视图之后,因为它是一个webview

在不使用单独的活动和意图的情况下,实现闪屏淡出动画的最佳方法是什么

下面是我主要活动中的工作代码

package com.chris.myapp;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import com.chris.myapp.adapter.ActionsAdapter;
import com.chris.myapp.fragment.WebViewFragment;
import shared.ui.actionscontentview.ActionsContentView;
import android.app.*;
import android.os.*;

public class MainActivity extends FragmentActivity {

    private static final String STATE_URI = "state:uri";

    private ActionsContentView viewActionsContentView;
    private MyPagerAdapter pageAdapter;
    private Dialog mSplashDialog;

    private Uri currentUri = WebViewFragment.DEFAULT_URI;
    @SuppressWarnings("deprecation")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        MyStateSaver data = (MyStateSaver) getLastNonConfigurationInstance();
        if (data != null) {
            // Show splash screen if still loading
            if (data.showSplashScreen) {
                showSplashScreen();
            }
            setContentView(R.layout.example);        

            // Rebuild your UI with your saved state here
        } else {
            showSplashScreen();
            setContentView(R.layout.example);
            // Do your heavy loading here on a background thread
        }

        viewActionsContentView = (ActionsContentView) findViewById(R.id.actionsContentView);
        viewActionsContentView.setSwipingType(ActionsContentView.SWIPING_EDGE);
        viewActionsContentView.setSpacingType(ActionsContentView.SPACING_ACTIONS_WIDTH);
        viewActionsContentView.setSpacingWidth(650);
        viewActionsContentView.setActionsSpacingWidth(0);

        pageAdapter = new MyPagerAdapter(getSupportFragmentManager());
        final ViewPager pager = (ViewPager) findViewById(R.id.myViewPager);
        pager.setAdapter(pageAdapter);
        pager.setPageMargin(20);
        pager.setPageMarginDrawable(R.color.pager_bg);

        final ListView viewActionsList = (ListView) findViewById(R.id.actions);
        final ActionsAdapter actionsAdapter = new ActionsAdapter(this);
        viewActionsList.setAdapter(actionsAdapter);
        viewActionsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapter, View v, int position,
                                    long flags) {
                final Uri uri = actionsAdapter.getItem(position);
                updateContent(uri);
                viewActionsContentView.showContent();
            }
        });

        if (savedInstanceState != null) {
            currentUri = Uri.parse(savedInstanceState.getString(STATE_URI));
        }

        updateContent(currentUri);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        outState.putString(STATE_URI, currentUri.toString());

        super.onSaveInstanceState(outState);
    }

    public void updateContent(Uri uri) {
        if (uri == null)
            return;

        final WebViewFragment webViewFragment = (WebViewFragment)
        pageAdapter.getItem(MyPagerAdapter.WEBVIEW_FRAGMENT_POSITION);
        webViewFragment.setUrl(uri.toString());
        webViewFragment.reload();
        currentUri = uri;
    }

     /**
     * Removes the Dialog that displays the splash screen
     */
    protected void removeSplashScreen() {
        if (mSplashDialog != null) {
            mSplashDialog.dismiss();
            mSplashDialog = null;
        }
    }

    /**
     * Shows the splash screen over the full Activity
     */
    protected void showSplashScreen() {
        mSplashDialog = new Dialog(this, R.style.SplashScreen);
        mSplashDialog.setContentView(R.layout.splashscreen);
        mSplashDialog.setCancelable(false);
        mSplashDialog.show();

        // Set Runnable to remove splash screen just in case
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    removeSplashScreen();
                }
            }, 3000);
    }

    /**
     * Simple class for storing important data across config changes
     */
    private class MyStateSaver {
        public boolean showSplashScreen = false;
        // Your other important fields here
    }


    private static long back_pressed;
    private Toast toast;
    @Override
    public void onBackPressed() {
        final WebViewFragment currentFragment = (WebViewFragment)
                pageAdapter.getItem(MyPagerAdapter.WEBVIEW_FRAGMENT_POSITION);
        if (currentFragment instanceof WebViewFragment) {
            final WebViewFragment webFragment = currentFragment;
            if (webFragment.onBackPressed())
                return;
        }

        if (back_pressed + 2000 > System.currentTimeMillis())
        {

            // need to cancel the toast here
            toast.cancel();

            // code for exit
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.addCategory(Intent.CATEGORY_HOME);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            finish();

        }
        else
        {
            // ask user to press back button one more time to close app 
            toast=  Toast.makeText(getBaseContext(), "Press again to exit", Toast.LENGTH_SHORT);
            toast.show();
            viewActionsContentView.showContent();
        }
        back_pressed = System.currentTimeMillis();
    }
}
package com.chris.myapp;
导入android.content.Intent;
导入android.net.Uri;
导入android.os.Bundle;
导入android.support.v4.app.FragmentActivity;
导入android.support.v4.view.ViewPager;
导入android.view.view;
导入android.widget.AdapterView;
导入android.widget.ListView;
导入android.widget.Toast;
导入com.chris.myapp.adapter.ActionsAdapter;
导入com.chris.myapp.fragment.WebViewFragment;
导入shared.ui.actionscontentview.actionscontentview;
导入android.app.*;
导入android.os.*;
公共类MainActivity扩展了FragmentActivity{
私有静态最终字符串状态_URI=“STATE:URI”;
私人行动内容视图视图行动内容视图;
专用MyPagerAdapter页面适配器;
专用对话框mSplashDialog;
私有Uri currentUri=WebViewFragment.DEFAULT\u Uri;
@抑制警告(“弃用”)
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
MyStateSaver数据=(MyStateSaver)GetLastNonConfiguration实例();
如果(数据!=null){
//如果仍在加载,则显示启动屏幕
if(数据显示屏幕){
showSplashScreen();
}
setContentView(R.layout.example);
//使用此处保存的状态重建UI
}否则{
showSplashScreen();
setContentView(R.layout.example);
//在后台线程上执行重载
}
viewActionsContentView=(ActionsContentView)findViewById(R.id.ActionsContentView);
viewActionsContentView.setSwipingType(ActionsContentView.SWIPING_EDGE);
viewActionsContentView.setSpacingType(ActionsContentView.SPACING\u ACTIONS\u WIDTH);
视图操作内容视图设置间隔宽度(650);
viewActionsContentView.SetActionsPacingWidth(0);
pageAdapter=新的MyPagerAdapter(getSupportFragmentManager());
final ViewPager pager=(ViewPager)findviewbyd(R.id.myViewPager);
寻呼机设置适配器(pageAdapter);
寻呼机设置页边距(20);
pager.setPageMarginDrawable(R.color.pager\u bg);
最终ListView视图操作列表=(ListView)findViewById(R.id.actions);
最终行动Sadapter ActionsAdapter=新行动Sadapter(本);
viewActionsList.setAdapter(actionsAdapter);
viewActionsList.setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
公共单击(适配器视图适配器,视图v,内部位置,
(长旗){
最终Uri=actionsAdapter.getItem(位置);
更新内容(uri);
viewActionsContentView.showContent();
}
});
如果(savedInstanceState!=null){
currentUri=Uri.parse(savedInstanceState.getString(STATE_Uri));
}
updateContent(当前URI);
}
@凌驾
SaveInstanceState上受保护的无效(束超出状态){
putString(STATE_URI,currentUri.toString());
super.onSaveInstanceState(超出状态);
}
public void updateContent(Uri){
if(uri==null)
回来
最终WebViewFragment WebViewFragment=(WebViewFragment)
pageAdapter.getItem(MyPagerAdapter.WEBVIEW\u片段\u位置);
webViewFragment.setUrl(uri.toString());
webViewFragment.reload();
currentUri=uri;
}
/**
*删除显示启动屏幕的对话框
*/
受保护的空隙清除PlashScreen(){
如果(mSplashDialog!=null){
mSplashDialog.disclose();
mSplashDialog=null;
}
}
/**
*显示整个活动的启动屏幕
*/
受保护的无效显示屏幕(){
mSplashDialog=新建对话框(此,R.style.SplashScreen);
mSplashDialog.setContentView(R.layout.splashscreen);
mSplashDialog.setCancelable(假);
mSplashDialog.show();
//设置Runnable以删除闪屏,以防万一
最终处理程序=新处理程序();
handler.postDelayed(新的Runnable(){
@凌驾
公开募捐{
移除PlashScreen();
}
}, 3000);
}
/**
*用于跨配置更改存储重要数据的简单类
*/
私有类MyStateSaver{
公共布尔showSplashScreen=false;
//你的其他重要领域在这里
}
私人静长背压;
私人吐司;
@凌驾
public void onBackPressed(){
最终WebViewFragment currentFragment=(WebViewFragment)
pageAdapter.getItem(MyPagerAdapter.WEBVIEW\u片段\u位置);
if(WebViewFragment的currentFragment实例){
最终WebViewFragment webFragment=currentFragment;
if(webFragment.onBackPressed())
回来
}
如果(按back_+2000>System.currentTimeMillis())
{
//我需要取消这里的祝酒辞
toast.cancel();
//出口代码
意向意向=新意向(意向.行动\主要);
intent.addCategory(intent.CATEGORY_HOME);
intent.setFlags(intent.FLAG\u活动\u新任务);
星触觉(意向);
完成();
}
其他的
{
//要求用户再按一次后退按钮到c
  public void removeSplashScreen() {
          if (mSplashDialog != null && mSplashDialog.isShowing()) {
            final MainActivity that = this;
            Runnable runnable = new Runnable() {
              public void run() {
                AnimationListener animationListener = new AnimationListener() {

                  public void onAnimationEnd(Animation animation) {
                    that.mSplashDialog.dismiss();
                    that.mSplashDialog = null;
                  }

                @Override
                public void onAnimationRepeat(Animation animation) {
                    // TODO Auto-generated method stub
                }

                @Override
                public void onAnimationStart(Animation animation) {
                    // TODO Auto-generated method stub
                }

                };
                AlphaAnimation splashDismissAnimation = new AlphaAnimation(1.0f, 0.0f);
                splashDismissAnimation.setAnimationListener(animationListener);
                splashDismissAnimation.setDuration(750);  // Gives app some time to init.

                View view = ((ViewGroup) ((Dialog) that.mSplashDialog).getWindow().getDecorView().getRootView()).getChildAt(0);
                view.setBackgroundColor(Color.TRANSPARENT);
                view.setBackgroundResource(android.R.color.transparent);
                view.startAnimation(splashDismissAnimation);
              }
            };
            this.runOnUiThread(runnable);
          }
        }