分享

FinestWebView:可自定义的WebView

 jnstyle 2016-07-16

最近在筹备写一个 干货集中营 的第三方Android客户端,考虑到该Api返回的数据大多是 Github 上的一些优秀的项目的地址,所以想找到一个WebView来打开该网站,但是Android官方提供的WebView不好使用,幸运的是找到了这样一款封装了WebView的库。

Github:https://github.com/TheFinestArtist/FinestWebView-Android

优点:
- 创建者模式
- Material design & Pre-made icons
- 自定义主题 & 自定义切换动画
- toolbar & actionbar 的支持
- SwipeRefreshLayout & Progressbar
- 支持界面旋转
- 自定义字体


效果图:
这里写图片描述

使用步骤:

1.在app的build.gradle文件添加:

dependencies { 
        compile 'com.thefinestartist:finestwebview:1.0.6'
}
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

2.在AndroidManifest.xml文件中注册activity和声明权限

<uses-permission android:name="android.permission.INTERNET" />

<activity
    android:name="com.thefinestartist.finestwebview.FinestWebViewActivity"
    android:configChanges="keyboardHidden|orientation|screenSize"
    android:screenOrientation="sensor"
    android:theme="@style/FinestWebViewTheme.Light" />
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

3.直接使用默认的WebVIew

new FinestWebView.Builder(activity).show(url);
  • 1
  • 1

通过以上步骤就可以简单的使用该FinestWebView 了。

不过,作为一个可以自定义的FinestWebView ,当然给我们提供了一些可以让我们设置显示和功能的方法。

自定义选项
有两种自定义 FinestWebView 的方法:

1.通过编写主题

<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/accent</item>
    <item name="android:textColorPrimary">@color/primary_text</item>
    <item name="android:textColorSecondary">@color/secondary_text</item>
    <item name="windowActionModeOverlay">true</item>
</style>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
<activity
    android:name="com.thefinestartist.finestwebview.FinestWebViewActivity"
    android:theme="@style/AppTheme.NoActionBar" />
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

2.通过Builder提供的方法
theme(主题)
StatusBar(状态栏)
Toolbar(工具栏)
ImageButton(关闭、菜单、向前、向后等按钮)
SwipeRefreshLayout (下拉刷新)
Divider(分割线)
Title(标题)
Url(地址)
Menu(菜单)
WebView

详情见 Github README.md页面

3.使用自定义字体
把字体文件放置到 assets/fonts文件夹下

在代码中使用:

new FinestWebView.Builder(activity)
    .titleFont("Roboto-Medium.ttf")
    .urlFont("Roboto-Regular.ttf")
    .menuTextFont("Roboto-Medium.ttf")
    .show(url);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5
  1. 自定义动画
    除了使用该库提供的动画外,还可以使用自定义的动画
new FinestWebView.Builder(activity)
    .setCustomAnimations(R.anim.activity_open_enter, R.anim.activity_open_exit, R.anim.activity_close_enter, R.anim.activity_close_exit)
    .show(url);
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

动画集合,设置多个动画

.setCustomAnimations(R.anim.activity_open_enter, R.anim.activity_open_exit, R.anim.activity_close_enter, R.anim.activity_close_exit)
.setCustomAnimations(R.anim.fragment_open_enter, R.anim.fragment_open_exit, R.anim.fragment_close_enter, R.anim.fragment_close_exit)
.setCustomAnimations(R.anim.slide_up, R.anim.hold, R.anim.hold, R.anim.slide_down)
.setCustomAnimations(R.anim.slide_left_in, R.anim.hold, R.anim.hold, R.anim.slide_right_out)
.setCustomAnimations(R.anim.fade_in_fast, R.anim.fade_out_medium, R.anim.fade_in_medium, R.anim.fade_out_fast)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5

原文链接:http://www.jianshu.com/p/f88c723d3d87

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多