android 炫酷页面,Android绘制炫酷引导界面

一个超炫的引导界面,分享给大家

89c7d0b9ef96bf0ad2eb923e48f91778.gif

代码:

MainActivity.java

package com.bzu.gxs.webview1;

import android.app.Activity;

import android.os.Build;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.KeyEvent;

import android.view.Menu;

import android.view.MenuItem;

public class MainActivity extends Activity {

private MyWebView myWebView;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

myWebView = (MyWebView) findViewById(R.id.webView);

myWebView.getSettings().setJavaScriptEnabled(true);

init();

myWebView.loadUrl("http://h5.eqxiu.com/s/F93iW6fu");

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

getMenuInflater().inflate(R.menu.my, menu);

return true;

}

@Override

public boolean onOptionsItemSelected(MenuItem item) {

int id = item.getItemId();

if (id == R.id.action_settings) {

return true;

}

return super.onOptionsItemSelected(item);

}

@Override

public boolean onKeyDown(int keyCode, KeyEvent event) {

if (keyCode == KeyEvent.KEYCODE_BACK && myWebView.canGoBack()) {

myWebView.goBack();

return true;

}

return super.onKeyDown(keyCode, event);

}

public void init(){

if(Build.VERSION.SDK_INT >= 19) {

myWebView.getSettings().setLoadsImagesAutomatically(true);

} else {

myWebView.getSettings().setLoadsImagesAutomatically(false);

}

}

}

MyWebView.java

package com.bzu.gxs.webview1;

import android.content.Context;

import android.util.AttributeSet;

import android.view.LayoutInflater;

import android.webkit.WebChromeClient;

import android.webkit.WebView;

import android.webkit.WebViewClient;

import android.widget.ProgressBar;

import android.widget.Toast;

/**

* Created by GXS on 2016/5/12.

*/

public class MyWebView extends WebView{

private ProgressBar progressBar;

private Context mContext;

public MyWebView(Context context, AttributeSet attributeSet) {

super(context,attributeSet);

mContext = context;

progressBar = (ProgressBar) LayoutInflater.from(context).inflate(R.layout.progressbar,null);

progressBar.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,6,0,0));

addView(progressBar);

setWebChromeClient(new WebChromeClient());

setWebViewClient(new WebViewClient(){

@Override

public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {

Toast.makeText(mContext,"Gxs"+description,Toast.LENGTH_SHORT).show();

}

});

this.getSettings().setBuiltInZoomControls(true);

this.getSettings().setUseWideViewPort(true);

}

public class WebChromeClient extends android.webkit.WebChromeClient {

@Override

public void onProgressChanged(WebView view, int newProgress) {

if (newProgress == 100) {

progressBar.setVisibility(GONE);

} else {

if (progressBar.getVisibility() == GONE)

progressBar.setVisibility(VISIBLE);

progressBar.setProgress(newProgress);

}

super.onProgressChanged(view,newProgress);

}

}

@Override

protected void onScrollChanged(int l, int t, int oldl, int oldt) {

LayoutParams layoutParams = (LayoutParams) progressBar.getLayoutParams();

layoutParams.x = l;

layoutParams.y = t;

progressBar.setLayoutParams(layoutParams);

super.onScrollChanged(l, t, oldl, oldt);

}

}

activity_main.xml

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context="com.bzu.gxs.webview1.MainActivity">

android:id="@+id/webView"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:text="Hello World!" />

progressbar.xml

android:id="@+id/ProgressBar"

style="?android:attr/progressBarStyleHorizontal"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:indeterminate="false"

android:maxHeight="10dip"

android:minHeight="10dip"

android:progress="50"

android:progressDrawable="@drawable/greenprogress" />

注意:需要在清单文件 AndroidManifest.xml 中加入:

以上就是本文的全部内容,希望能给大家一个参考,也希望大家多多支持脚本之家。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值