在启用斜杠时加载Webview

时间:2016-11-27 08:13:29

标签: java android webview

Android工作室相当新,但是我遇到了一个问题,我的 WebView 加载时间太长,所以我创建了一个4秒的启动画面并计划用这个来覆盖加载闪屏。但我真的不知道如何让它重叠,所以 WebView 可以加载到启动画面后面。  我的启动画面的java

public class MainActivity extends ActionBarActivity {
private static int SPLASH_TIME_OUT = 4000;

BottomBar mBottomBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run(){
            Intent homeIntent = new Intent(MainActivity.this, HomeActivity.class);
            startActivity(homeIntent);
            finish();
        }
    },SPLASH_TIME_OUT);
    getWindow().getDecorView().setBackgroundColor(Color.WHITE);

}

}

然后我还有一个底栏,用webview导航到第一个framgment,java如下所示     公共类HomeActivity扩展了ActionBarActivity {

BottomBar mBottomBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    getWindow().getDecorView().setBackgroundColor(Color.WHITE);
    mBottomBar = BottomBar.attach(this,savedInstanceState);
    mBottomBar.setItemsFromMenu(R.menu.menu_main,new OnMenuTabClickListener() {
        @Override
        public void onMenuTabSelected(@IdRes int i) {
            if(i==R.id.Bottombaritemone) {
                    HomeFragment f = new HomeFragment();
                getSupportFragmentManager().beginTransaction().replace(R.id.frame, f).commit();
            }
            else if(i==R.id.Bottombaritemtwo)
            {
                SearchFragment f =new SearchFragment();
                getSupportFragmentManager().beginTransaction().replace(R.id.frame,f).commit();
            }
            else if(i==R.id.Bottombaritemthree)
            {
                AccountFragment f =new AccountFragment();
                getSupportFragmentManager().beginTransaction().replace(R.id.frame,f).commit();
            }

        }

        @Override
        public void onMenuTabReSelected(@IdRes int i) {

        }
    });
    mBottomBar.mapColorForTab(0,"#F2F2F2");
    mBottomBar.mapColorForTab(1,"#F2F2F2");
    mBottomBar.mapColorForTab(2,"#F2F2F2");
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

最后是第一个HomeFragment中我的webview的java

公共类HomeFragment扩展Fragment {     WebView my2WebView;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup        container,Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.home,container,false);
    getLoaderManager();
    my2WebView = (WebView) view.findViewById(R.id.webView1);
    WebSettings webSettings = my2WebView.getSettings();
    my2WebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
    webSettings.setUseWideViewPort(true);
    webSettings.setSavePassword(true);
    webSettings.setEnableSmoothTransition(true);
    webSettings.setJavaScriptEnabled(true);
    webSettings.getLoadsImagesAutomatically();
    my2WebView.loadUrl("http://www.fidellaglobal.com/feed");
    my2WebView.setWebViewClient(new WebViewClient());
    return view;

}

那么在启动启动画面时,如何在第一个片段中加载webview?谢谢你:))

1 个答案:

答案 0 :(得分:0)

最初将 WebView 可见性设置为在布局文件中不可见。在具有延迟处理程序的同一屏幕中添加 WebView

new Handler().postDelayed(new Runnable() {
    @Override
    public void run(){
        // Make your webview visible
       mWebView.setVisibility(View.VISIBLE);
    }
},SPLASH_TIME_OUT);