小编W3h*_*hri的帖子

Android M:以编程方式撤消权限

我目前正在玩android m的新权限系统.我计划的是在我的应用内设置中添加一个屏幕,用户可以在其中授予或撤消权限.

屏幕看起来像常规系统设置屏幕,但会有其他信息,为什么我的应用程序需要特定权限.此设置屏幕将是文档中建议的常规权限处理的补充.

工作流程将是:

  • 授予权限:打开系统对话框以授予/撤消(如此处建议)
  • 撤消权限:以编程方式撤消它

所以我的问题是,可以以编程方式撤销权限吗?我搜索了很多,但没有得到一些结果.

android android-permissions android-6.0-marshmallow

23
推荐指数
3
解决办法
1万
查看次数

片段在replace()上具有默认的白色背景而不是透明的

我在使用碎片时遇到了一个奇怪的问题而且无法弄明白.

当我在MainActivity容器中替换片段时,有些会保留所需的透明背景,有些会显示默认的白色片段.我实际上希望我的所有片段都是透明的,并"使用"分配给MainActivity的背景.

例如: 片段A:白色背景

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:src="@drawable/logo"/>

    <de.mypackage.uielements.MyButton
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:text="@string/button_text"/>    

    **<!-- ListView to show news -->**
    <ListView
        android:id="@+id/listview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:dividerHeight="1dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginBottom="10dp"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

片段B:透明背景

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:id="@+id/listview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

main.xml中

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <!-- Background Image to be set programmatically, transparent being default -->
    <ImageView
        android:id="@+id/window_background_image_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:background="@android:color/transparent"/>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" …
Run Code Online (Sandbox Code Playgroud)

android background-image background-color android-listview android-fragments

12
推荐指数
1
解决办法
2万
查看次数