android-xml

Android: toggle text color of ToggleButton

荒凉一梦 提交于 2019-12-03 15:14:49
问题 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"?>

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 can I get the primary color from my app theme?

狂风中的少年 提交于 2019-12-03 12:44:24
问题 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

Match URIs with <data> like http://example.com/something in AndroidManifest

狂风中的少年 提交于 2019-12-03 12:25:20
I am struggling with the <data> element in the AndroidManifest.xml file to get my URI matching working. I want to match the following URIs: http://example.com/something http://example.com/foo http://example.com/foo/ but not http://example.com http://example.com/ http://example.com/something/else I got it mostly working with <data android:scheme="http" android:host="example.com" android:pathPattern="/..*" /> <data android:pathPattern="/..*/" /> but it still matches http://example.com/something/else . How can I exclude these? Unfortunately the wildcards that can be used for the pathPattern tag

Rectangle shape with two solid colors

我们两清 提交于 2019-12-03 12:09:46
I'd like to create a rectangle shape with two solid colors (horizontally) to achieve something like this: I heard about layer-list , i though i could use it to contains two rectangle with a different color but it seems that it only lays shapes vertically. Is there a way to achieve this using lalyer-list or should i use something totally different? I'd like to keep it simple with ability to change the shape colors at runtime. Thanks. You can create custom drawable for this. Just extend Drawable class. Here is a sample code which draws a rectangle like you wanted, you can provide any number of

Disabling the keyboard's send button when nothing has been typed yet [Android]

天涯浪子 提交于 2019-12-03 11:48:52
I'm creating a search option in an android application. After pressing "Search" on the screen-keyboard an event triggers which sends the query to the server. What I want to do is disable the "Search" button on the screen-keyboard when no text has been typed in it's corresponding EditText yet. I added this to the EditText : android:imeOptions="actionSearch" So that's why the keyboard has got a "Search" button in stead of the default "enter"/"done". (Just in case you where wondering). We cannot disable the action button on the android keyboard. You will have to settle with checking for empty

What limits are there on the number of Android resources?

拥有回忆 提交于 2019-12-03 11:10:47
One of our apps has several thousand small data files that we're currently packaging as assets. It would help our code if we could package them as raw resources. I have tried to track down what the limits are for the number of resources an app can have of each type, but I haven't found any documentation on this. Does anyone know what the limits are on the number of Android resources? After a lot of experimenting, it seems that you can have up to 16 bits worth of resources (65,536 resources) for each resource type. (There may be additional bits reserved for future use, which would reduce the

How to align CheckBox to the top of its description in Android

拈花ヽ惹草 提交于 2019-12-03 10:42:42
I would like to align CheckBox "symbol" to the top of its description. What I have now: What I want to have: Current xml: <CheckBox android:id="@+id/register_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/register_hint"/> I've tried to achieve this by manipulating layout_gravity attributes, but it doesn't work. heloisasim android:gravity="top" will fix the problem: <CheckBox android:id="@+id/register_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/register_hint" android:gravity=

set Background Image and xml Resource

喜你入骨 提交于 2019-12-03 08:29:57
I am using the following below code to round the corners of RelativeLayout. I save this as mybackground.xml in drawable folder. It's working fine for rounding the corner but the problem is that I also want to add an transparent image as a background of my RelativeLayout. How can I achieve both things? How can I use an image and a drawable xml (for rounding the corner) at the same time for a RelativeLayout ... <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:padding="10dp"> <corners android

Using ImageView as background for an Android Layout

≯℡__Kan透↙ 提交于 2019-12-03 08:16:51
I want to take advantage of the scaleType property, which I cannot use if I set my image using the background property on the LinearLayout . I've tried using a LinearLayout with 2 children: the first is an ImageView (for the background image) and the second child is another LinearLayout containing TextViews , Buttons, etc. But the result is just the image followed by the other views. Is it possible to float the nested LinearLayout over the ImageView somehow? I know that there's lots of variations on this question around, but I haven't found anything that's helped me yet. If I've missed