android-custom-attributes

Custom XML attributes without custom View in Fragment

我怕爱的太早我们不能终老 提交于 2020-01-01 05:18:13
问题 I'm trying to add custom XML attributes in existing View Adding them to a custom View is not a big deal but I don't know how to access those attributes in a "basic" View (e.g. TextView, LinearLayout, ImageView ...) And this is more difficult when there are Fragment and / or Library project involved So far here is my code Customs attributes definitions and XML (attrs.xml and the layout): <?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="StarWars"> <attr name="jedi"

How do you add user defined properties/values in to the Android manifest file?

拜拜、爱过 提交于 2019-12-17 22:13:41
问题 I want to add a custom attribute / property into the manifest file, and be able to read it at run time. I want to do this so I can customize the app's behavior via these manifest properties. How can this be done? 回答1: You can add meta-data to your AndroidManifest.xml file and then read that in your application. Write the data like so: <meta-data android:value="bar" android:name="foo"></meta-data> And read the data like so: ApplicationInfo ai = context.getPackageManager().getApplicationInfo

Same-named attributes in attrs.xml for custom view

为君一笑 提交于 2019-12-17 17:27:13
问题 I'm writing a few custom views which share some same-named attributes. In their respective <declare-styleable> section in attrs.xml I'd like to use the same names for attributes: <?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="MyView1"> <attr name="myattr1" format="string" /> <attr name="myattr2" format="dimension" /> ... </declare-styleable> <declare-styleable name="MyView2"> <attr name="myattr1" format="string" /> <attr name="myattr2" format="dimension" /> ... <

give space between text and underline with customview android

与世无争的帅哥 提交于 2019-12-10 23:26:19
问题 I want an underline below OPTING like below, but when i create this will the help of customview, underline appears just below opting but i want some space between text and line like image I had created a Custom view, in which a word will searched in a string if that is found, then that corresponding text will be underlined but the only thing i want is to give some space between underline and text, My class is as follows, import android.content.Context; import android.content.res.TypedArray;

How to get attributes with namespace “android” in custom TextView

旧街凉风 提交于 2019-12-10 14:55:37
问题 In custom TextView I'm trying to obtain value of a text attribute (for example). TypedArray values = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.TextView); String text = values.getString(com.android.internal.R.styleable.TextView_text); But I'm getting this error message: package com.android.internal.R does not exist So how to retrieve "default" attributes of TextView? 回答1: The internal.R class isn't visible so you can only read them through their accessor methods

Custom XML attributes without custom View in Fragment

99封情书 提交于 2019-12-03 14:24:56
I'm trying to add custom XML attributes in existing View Adding them to a custom View is not a big deal but I don't know how to access those attributes in a "basic" View (e.g. TextView, LinearLayout, ImageView ...) And this is more difficult when there are Fragment and / or Library project involved So far here is my code Customs attributes definitions and XML (attrs.xml and the layout): <?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="StarWars"> <attr name="jedi" format="string" /> <attr name="rank" format="string" /> </declare-styleable> <LinearLayout xmlns:android=

How do you add user defined properties/values in to the Android manifest file?

核能气质少年 提交于 2019-11-28 17:49:41
I want to add a custom attribute / property into the manifest file, and be able to read it at run time. I want to do this so I can customize the app's behavior via these manifest properties. How can this be done? P.Melch You can add meta-data to your AndroidManifest.xml file and then read that in your application. Write the data like so: <meta-data android:value="bar" android:name="foo"></meta-data> And read the data like so: ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); Object value = (Object)ai.metaData.get("foo")

Same-named attributes in attrs.xml for custom view

落爺英雄遲暮 提交于 2019-11-28 03:37:06
I'm writing a few custom views which share some same-named attributes. In their respective <declare-styleable> section in attrs.xml I'd like to use the same names for attributes: <?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="MyView1"> <attr name="myattr1" format="string" /> <attr name="myattr2" format="dimension" /> ... </declare-styleable> <declare-styleable name="MyView2"> <attr name="myattr1" format="string" /> <attr name="myattr2" format="dimension" /> ... </declare-styleable> </resources> I'm getting an error saying that myattr1 and myattr2 are already