动态获取权限模板
//自定义方法
public static void checkPerssion(Activity activity) {
// Check if we have write permission
int permission = context.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permission != PackageManager.PERMISSION_GRANTED) {
// We don't have permission so prompt the user
activity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_EXTERNAL_STORAGE);
return;
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
{
switch (requestCode) {
case REQUEST_EXTERNAL_STORAGE:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
}
else {
// Permission Denied
Toast.makeText(Welcome.this, "请开启读写权限", Toast.LENGTH_SHORT).show();
}
break;
default:
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
透明状态栏
在主题中加一个item
<style name="AppTheme.Main" parent="AppTheme.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
</style>
隐藏标题栏
activity继承AppCompatActivity
oncreat中getSupportActionBar().hide();
设置屏方向
在 BaseActivity 的 onCreate() 方法中添加下面这句话setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); //竖屏
setRequestedOrientation(ActivityInfo.SCREEN_VERTICAL_PORTRAIT); //竖屏 vertical
网友评论