草庐IT

android - 工厂 : Drawable already belongs to another owner

coder 2023-12-26 原文

我在 fragment 上添加了两个 float 操作按钮,但总是出现以下错误:

向 LayerDrawable 添加了无效的可绘制对象! Drawable 已经属于另一个所有者,但不公开常量状态

<RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_margin="30dp"
android:layout_width="match_parent"
android:layout_height="match_parent">

    <ScrollView
        android:layout_weight="1"
        android:id="@+id/scrollView"
        android:layout_marginRight="30dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/layout_main_account">

            <TextView
                android:text="Name"
                android:textStyle="bold"
                android:layout_marginTop="30dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/tv_activity_main_account_name_label"/>

            <EditText
                android:enabled="false"
                android:inputType="none"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/et_activity_main_account_name_label_value"/>
        </LinearLayout>
    </ScrollView>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <View
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="0dp"/>

        <android.support.design.widget.FloatingActionButton
            android:backgroundTint="#000"
            android:layout_marginBottom="5dp"
            android:layout_marginRight="10dp"
            app:layout_anchorGravity="bottom"
            android:layout_width="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_edit_account"
            android:id="@+id/fbtn_activity_main_account_edit_account"/>

        <android.support.design.widget.FloatingActionButton
            android:backgroundTint="#000"
            android:layout_marginBottom="5dp"
            app:layout_anchorGravity="bottom"
            android:layout_width="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_home_account"
            android:id="@+id/fbtn_activity_main_account_manage_addresses"
            app:layout_anchor="@id/fbtn_activity_main_account_edit_account"/>

    </LinearLayout>
</RelativeLayout>

drawable -> ic_edit_account.xml

<vector android:height="24dp" android:viewportHeight="60.017"
android:viewportWidth="60.017" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FFFFFF" android:pathData="M59.144,3.731l-2.85,-2.851c-1.164,-1.161 -3.057,-1.162 -4.221,0.001l-3.126,3.126H0v56h56V11.097l0.305,-0.305l0,0l2.839,-2.839C60.308,6.789 60.308,4.895 59.144,3.731zM20.047,36.759l3.22,3.22l-4.428,1.208L20.047,36.759zM52.062,12.206L47.82,7.964l1.414,-1.414l4.243,4.242L52.062,12.206zM50.648,13.62L25.192,39.076l-4.242,-4.242L46.406,9.378L50.648,13.62zM54,13.097v44.91H2v-52h44.947L18.829,34.127l-0.188,0.188l-2.121,7.779l-1.226,1.226c-0.391,0.391 -0.391,1.023 0,1.414c0.195,0.195 0.451,0.293 0.707,0.293s0.512,-0.098 0.707,-0.293l1.226,-1.226l7.779,-2.123l26.351,-26.35h0l0.447,-0.447L54,13.097zM57.73,6.539l-2.839,2.839l-4.243,-4.243l2.839,-2.839c0.384,-0.384 1.009,-0.383 1.393,0l2.85,2.85C58.114,5.529 58.114,6.155 57.73,6.539z"/>
</vector>

drawable -> ic_home_account.xml

<vector android:height="24dp" android:viewportHeight="512"
android:viewportWidth="512" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FFFFFFFF" android:pathData="M506.555,208.064L263.859,30.367c-4.68,-3.426 -11.038,-3.426 -15.716,0L5.445,208.064c-5.928,4.341 -7.216,12.665 -2.875,18.593s12.666,7.214 18.593,2.875L256,57.588l234.837,171.943c2.368,1.735 5.12,2.57 7.848,2.57c4.096,0 8.138,-1.885 10.744,-5.445C513.771,220.729 512.483,212.405 506.555,208.064z"/>
<path android:fillColor="#FFFFFFFF" android:pathData="M442.246,232.543c-7.346,0 -13.303,5.956 -13.303,13.303v211.749H322.521V342.009c0,-36.68 -29.842,-66.52 -66.52,-66.52s-66.52,29.842 -66.52,66.52v115.587H83.058V245.847c0,-7.347 -5.957,-13.303 -13.303,-13.303s-13.303,5.956 -13.303,13.303v225.053c0,7.347 5.957,13.303 13.303,13.303h133.029c6.996,0 12.721,-5.405 13.251,-12.267c0.032,-0.311 0.052,-0.651 0.052,-1.036v-128.89c0,-22.009 17.905,-39.914 39.914,-39.914s39.914,17.906 39.914,39.914v128.89c0,0.383 0.02,0.717 0.052,1.024c0.524,6.867 6.251,12.279 13.251,12.279h133.029c7.347,0 13.303,-5.956 13.303,-13.303V245.847C455.549,238.499 449.593,232.543 442.246,232.543z"/>
</vector>

build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
    applicationId "com.atta"
    minSdkVersion 23
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

// retrofit, gson
implementation 'com.google.code.gson:gson:2.6.2'
implementation 'com.squareup.okhttp3:okhttp:3.8.0'
implementation 'com.squareup.retrofit2:retrofit:2.0.2'
implementation 'com.basgeekball:awesome-validation:4.1'
implementation 'com.squareup.retrofit2:converter-gson:2.0.2'
implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0'
}

注意:每个 drawable 只使用一次。

以下线程没有解决我的问题:

Drawable already belongs to another owner but does not expose a constant state

发现问题:以下属性导致异常:

android:backgroundTint="#000"

如果我不使用它,FAB 上有一个粉红色的背景:(

最佳答案

固定:

在顶部布局中添加了xmlns:app="http://schemas.android.com/apk/res-auto"

使用 app:backgroundTint="@color/colorFABTint" 而不是 android:backgroundTint="#000"

colors.xml

中添加了以下行
<color name="colorFABTint">#000000</color>

生成的 xml:

<RelativeLayout
    android:layout_margin="30dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android">

<android.support.design.widget.FloatingActionButton
                android:layout_marginBottom="5dp"
                app:layout_anchorGravity="bottom"
                android:layout_width="wrap_content"
                android:layout_gravity="bottom|end"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_home_account"
                app:backgroundTint="@color/colorFABTint"
                android:id="@+id/fbtn_activity_main_account_manage_addresses"
                app:layout_anchor="@id/fbtn_activity_main_account_edit_account"/>

关于android - 工厂 : Drawable already belongs to another owner,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51467857/

有关android - 工厂 : Drawable already belongs to another owner的更多相关文章

  1. ruby-on-rails - Railstutorial : db:populate vs. 工厂女孩 - 2

    在railstutorial中,作者为什么选择使用这个(代码list10.25):http://ruby.railstutorial.org/chapters/updating-showing-and-deleting-usersnamespace:dbdodesc"Filldatabasewithsampledata"task:populate=>:environmentdoRake::Task['db:reset'].invokeUser.create!(:name=>"ExampleUser",:email=>"example@railstutorial.org",:passwo

  2. 安卓apk修改(Android反编译apk) - 2

    最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路

  3. ruby-on-rails - 工厂女孩/Rails : Generator to create a factory for existing model? - 2

    我在我的Rails项目中使用rspec_rails和factory_girl_railsgem。所有模型都已创建。是否有我可以运行的生成器来为现有模型创建工厂文件?例如:我已经有了一个Blog模型。RSpec允许我通过简单地运行以下命令在spec/models/blog_spec.rb生成一个模型规范文件:railsgeneraterspec:modelblog是否有我可以在命令行中运行的生成器,它会为这个现有模型生成工厂文件,位于:spec/factories/blogs.rb?我在factory_girl_rails中没有看到任何关于发电机的提及文档。

  4. ruby-on-rails - 我如何在 FactoryGirl 中为循环关联创建工厂? - 2

    我在尝试为我在项目中定义的某些对象和关联创建工厂时遇到了问题。我有一种循环关联,其中一个对象与另外两个随后连接在一起的对象关联。+--------------++-------------+|||||TestCase+--------->|TestDataGrid|||||+------+-------++------+------+||||||vv+--------------++--------------+|||||||||TestVariable||TestDataSet|||||+------+-------++------+-------+|||||||||+-------

  5. ruby-on-rails - Rails 3.1,工厂女孩错误 - 2

    已修复。Rails中有一个错误。参见https://github.com/rails/rails/issues/2333我对FactoryGirlRails和Rails3.1.0.rc5有疑问当我多次执行user=FactoryGirl.create(:user)时出现错误。Failure/Error:user=FactoryGirl.create(:user)NameError:uninitializedconstantUser::User#./app/models/user.rb:17:in`generate_token'#./app/models/user.rb:4:in`blo

  6. ruby-on-rails - FactoryGirl工厂特征内的序列不使用主序列计数器 - 2

    我有以下工厂:FactoryGirl.definedofactory:foodosequence(:name){|n|"Foo#{n}"}trait:ydosequence(:name){|n|"Fooy#{n}"}endendend如果我跑create:foocreate:foocreate:foo,:y我得到Foo1,Foo2,Fooy1。但我想要Foo1,Foo2,Fooy3。我怎样才能做到这一点? 最佳答案 经过smile2day'sanswer的一些提示后和thisanswer,我得出以下解决方案:FactoryGirl.

  7. ruby-on-rails - 之前的工厂女孩​​(:create) callback not creating associations - 2

    我有一个FactoryGirl工厂,它创建一个Order但before(:create)回调不会创建关联的工厂对象:父类classOrder子类classOrderLine工厂Factory:orderdo...ignoredonumber_or_order_lines1endbefore(:create)do|order,evaluator|FactoryGirl.create_list:order_line,evaluator.number_or_order_lines,order:orderendendFactory:order_linedoassociation:userass

  8. ruby-on-rails - 命名空间类的 FactoryGirl 工厂 - 2

    非常感谢任何证明或反驳我的想法的文档链接;我好像找不到。据我所知,如果您有一个带有Product模型的Rails应用程序,您可以将FactoryGirl工厂定义为FactoryGirl.definedofactory:productdo#stuffsendend然后使用(RSpec示例)调用您的工厂进行测试let(:product){FactoryGirl.create(:product)}但你也可以调用它let(:product){FactoryGirl.create(Product)}如果您希望使用RSpec的described_class帮助程序让您的模型测试更加动态并且可以自由

  9. Android Studio开发之使用内容组件Content获取通讯信息讲解及实战(附源码 包括添加手机联系人和发短信) - 2

    运行有问题或需要源码请点赞关注收藏后评论区留言一、利用ContentResolver读写联系人在实际开发中,普通App很少会开放数据接口给其他应用访问。内容组件能够派上用场的情况往往是App想要访问系统应用的通讯数据,比如查看联系人,短信,通话记录等等,以及对这些通讯数据及逆行增删改查。首先要给AndroidMaifest.xml中添加响应的权限配置 下面是往手机通讯录添加联系人信息的例子效果如下分成三个步骤先查出联系人的基本信息,然后查询联系人号码,再查询联系人邮箱代码 ContactAddActivity类packagecom.example.chapter07;importandroid

  10. Android 10.0 设置默认launcher后安装另外launcher后默认Launcher失效的功能修复 - 2

    1.前言 在10.0的系统rom定制化开发中,在系统中有多个launcher的时候,会在开机进入launcher的时候弹窗launcher列表,让用户选择进入哪个launcher,这样显得特别的不方便所以产品开发中,要求用RoleManager的相关api来设置默认Launcher,但是在设置完默认Launcher以后,在安装一款Launcher的时候,默认Launcher就会失效,在系统设置的默认应用中Launcher选项就为空,点击home键的时候会弹出默认Launcher列表,让选择进入哪个默认Launcher.所以需要从安装Launcher的流程来分析相关的设置。来解决问题设置默认La

随机推荐