1.添加依赖
compile 'me.weyye.hipermission:library:1.0.2'
2.权限申请代码(默认样式)
List<PermissonItem> permissonItems = new ArrayList<PermissonItem>();
//若权限申请多条 自己在下面添加既可
//注意:要记的给自己的权限添加图片哦
permissonItems.add(new PermissonItem(Manifest.permission.CAMERA, "照相机", R.drawable.permission_ic_memory));
permissonItems.add(new PermissonItem(Manifest.permission.ACCESS_FINE_LOCATION, "定位", R.drawable.permission_ic_location));
HiPermission.create(MainActivity.this)
.permissions(permissonItems)
.checkMutiPermission(new PermissionCallback() {
@Override
public void onClose() {
}
@Override
public void onFinish() {
}
@Override
public void onDeny(String permisson, int position) {
showToast("onDeny");
}
@Override
public void onGuarantee(String permisson, int position) {
showToast("onGuarantee");
}
});
3.权限申请代码(自定义样式)
List<PermissonItem> permissonItems = new ArrayList<PermissonItem>();
permissonItems.add(new PermissonItem(Manifest.permission.CAMERA, "照相机", R.drawable.permission_ic_camera));
permissonItems.add(new PermissonItem(Manifest.permission.ACCESS_FINE_LOCATION, "定位", R.drawable.permission_ic_location));
HiPermission.create(MainActivity.this)
.title("亲爱的上帝")
.permissions(permissonItems)
.filterColor(ResourcesCompat.getColor(getResources(), R.color.colorPrimary, getTheme()))
.msg("为了保护世界的和平,开启这些权限吧!\\n你我一起拯救世界!")
.style(R.style.PermissionBlueStyle)
.checkMutiPermission(new PermissionCallback() {
@Override
public void onClose() {
showToast("用户关闭权限申请");
}
@Override
public void onFinish() {
showToast("所有权限申请完成");
}
@Override
public void onDeny(String permisson, int position) {
}
@Override
public void onGuarantee(String permisson, int position) {
}
});
3.1.自定义style(values->styles)
<style name="PermissionBlueStyle">
<item name="PermissionTitleColor">@color/colorPrimaryDark</item>
<item name="PermissionMsgColor">@color/colorPrimary</item>
<item name="PermissionItemTextColor">@color/colorPrimary</item>
<item name="PermissionButtonBackground">@drawable/shape_btn</item>
<item name="PermissionBackround">@drawable/shape_bg_white</item>
<item name="PermissionButtonTextColor">@android:color/white</item>
</style>
3.2.自定义按钮shape(drable->shape_btn)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="10dp" />
<solid android:color="#3B9DFF" />
</shape>
如有疑问请戳这里 東方月初
网友评论