android-xml

Difference between ?selectableItemBackground, ?android:selectableItemBackground and ?android:attr/selectableItemBackground in Android?

南楼画角 提交于 2019-12-03 08:00:51
问题 What is the difference between: android:background="?selectableItemBackground" android:background="?attr/selectableItemBackground" android:background="?android:selectableItemBackground" android:background="?android:attr/selectableItemBackground" in Android? 回答1: Here, android:background="?selectableItemBackground" is attribute reference from appCompat library so it is applied to older versions of android and doesn't need android prefix. android:background="?android:selectableItemBackground"

Create, store and inflate custom layout in runtime

时光怂恿深爱的人放手 提交于 2019-12-03 07:04:52
I'm trying to find a solution for the following problem. The application I work on requires a possibility for user to produce custom UI (layout of simple widgets) via custom UI builder. So, user may stack widgets (images, mostly. But TextViews and EditText, as well) on canvas, move them around, etc. UI have to be stored in a database for future use. So, there should be some mechanism for loading and inflating of this UI. This is the main problem. My first idea was to rely on standard Android layout mechanism. Unfortunately, the LayoutInflater works with XML compiled into a binary form. And as

Resource arrays [duplicate]

a 夏天 提交于 2019-12-03 06:28:46
问题 This question already has answers here : Storing R.drawable IDs in XML array (6 answers) Closed 2 years ago . Is there a way to define an array in XML in which the elements are resource references? For example (it doesn't work, but it explains what I want): <integer-array name="actions_images"> <item>@drawable/pencil</item> <item>@drawable/pencil</item> <item>@drawable/pencil</item> <item>@drawable/pencil</item> <item>@drawable/pencil</item> <item>@drawable/pencil</item> </integer-array> 回答1:

Android: toggle text color of ToggleButton

谁都会走 提交于 2019-12-03 05:50:38
To create a custom ToggleButton, I've defined a new style in /res/values/styles.xml : <style name="myToggleButton"> <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> <item name="android:textColor">#000000</item> <item name="android:background">@drawable/my_toggle_button</item> </style> and I then use a selector to specify how the button's states look in /res/drawable/my_toggle_button.xml : <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true">

Animate Two Layer Drawable Items Pre-Honeycomb

旧街凉风 提交于 2019-12-03 05:32:31
I am trying to animate two layers of a drawable to achieve the effect of the post-Honeycomb indeterminate progress indicator. The XML is very straightforward but it would seem that only one layer will animate when run on platforms prior to Honeycomb. <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <rotate android:drawable="@drawable/abs__spinner_48_outer_holo" android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0" android:toDegrees="1080" /> </item> <item> <rotate android:drawable="@drawable/abs__spinner_48_inner_holo" android:pivotX="50%" android

Tint / dim drawable on touch

痞子三分冷 提交于 2019-12-03 03:55:08
问题 The app I'm currently working on uses a lot of ImageViews as buttons. The graphics on these buttons use the alpha channel to fade out the edges of the button and make them look irregular. Currently, we have to generate 2 graphics for each button (1 for the selected/focused/pressed state and the other for the default unselected state) and use a StateListDrawable defined in an XML file for each button. While this works fine it seems extremely wasteful since all of the selected graphics are

Round cornered button with background color in android

好久不见. 提交于 2019-12-03 03:21:31
问题 I need to do round cornered button with background color change in android. How could i do that? Example link/code is much appreciated. 回答1: You want to use Android's Shape Drawables. http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape drawable/cool_button_background.xml <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="@dimen/corner_radius" /> <gradient

How can I get the primary color from my app theme?

。_饼干妹妹 提交于 2019-12-03 02:21:18
In my Android java code, how can I reference the color "colorPrimary" set in my theme? I have the following theme definition: <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <item name="colorPrimary">@color/myColor1</item> <item name="colorPrimaryDark">@color/myColor2</item> <item name="colorControlNormal">@color/myColor3</item> <item name="colorControlActivated">@color/myColor4</item> </style> I could reference the color resource directly (R.color.myColor1), but I would prefer to reference the theme's primaryColor setting, so that it stays consistent if the

How to retrieve 2D array from xml string resource for Android?

筅森魡賤 提交于 2019-12-03 01:43:35
Suppose I have stored a 2 dimensional array in android resource as shown below. How can I get them in a java collection like Arraylist? <resources> <string-array name="countries_array"> <item> <name>Bahrain</name> <code>12345</code> </item> <item> <name>Bangladesh</name> <code>54545</code> </item> <item> <name>India</name> <code>54455</code> </item> </string-array> </resources> For example in case of 1 dimensional array we can do it using getResources().getStringArray(R.array.countries_array); When the countries_array is like <resources> <string-array name="countries_array"> <item>Bahrain<

ImageView not keeping max height and width

寵の児 提交于 2019-12-03 00:58:49
I load an image into an ImageView using .setImageURI(selectedImageUri) that is retrieved from the user's photo gallery. I have the image view restrict the size with android:maxHeight="150dp" android:minHeight="150dp" android:maxWidth="150dp" android:minWidth="150dp" It's fine up until the you add the image from the gallery. The image then forgets about the max height and width. It is as wide as the display and there is a lot of space above and below the image. I had to add a scrollview just to see the image and scroll down. there is an even amount of space above and below. Has anyone run into