Is it possible to do something like the following?
<LinearLayout android:id="#android:id/empty"
android:background="?android:style/Widget.ListView.overScrollFooter"
>
Left out all the unimportant layout stuff. I'm wondering if it's possible to reference one of the individual attributes of defined in a style?
Edit for more info: The default styles and attributes for many widgets are defined by Android, and customized further by phone manufacturers. That's how they can customize how a basic android widget looks. In my example, the footer of a listView will look different on a Samsung phone than on a HTC phone or on a default Google phone.
I would like to grab the attribute defined in the listview style (specifically the overscrollfooter drawable attribute), and use it as a background for one of my views. Technically speaking, I have a programmatic solution for this, but it's clunky, and requires that I repeat that code every time I use this view (which is in a lot of places).
No, I think a style is an all or none kinda of deal. I would place the footer in it's own style and import it into your primary style. That frees it up to be used (alone) in yout LinearLayout.
Related
I'm curious to know whether it's possible to change the default spacing that's placed around MaterialCheckBox... or whether there are plans to allow for this.
Let's say, for the sake of example, I have a CheckBox defined with four TextViews around it (to the left, right, top and bottom of it) and I specify no margins on any of the five Views. If I define my app's theme as Theme.AppCompat.Light then this CheckBox is rendered with equal spacing around it as follows:
If I change the app's theme to Theme.MaterialComponents.Light and make no other changes to the app then the CheckBox is rendered as follows:
Note the unequal spacing which I would like to customise on a per-need basis. There's nothing mentioned in the MaterialCheckBox documentation and I can't see anything obvious in the class definition about being able to change this spacing.
(For what it's worth I'm using the latest version of the com.google.android.material:material library, i.e. 1.1.0-alpha03. And everything I've said above holds regardless of whether I define a CheckBox, AppCompatCheckBox or MaterialCheckBox in my layout. The key thing is changing the theme from Theme.AppCompat.Light to Theme.MaterialComponents.Light.)
This looks related to MaterialCheckBox enforcing a 48dp minTouchTargetSize for accessibility using android:minWidth in the CheckBox style (this should be added to the documentation). Setting android:minWidth to 0dp should work.
android:textAppearance allows you to apply an additional layer of styling for certain attributes on text views. I'm wondering whether the flexibility of this feature outweighs its complexity.
Is android:textAppearance required for any technical or visual reason?
What might be the consequences of relying solely on style throughout a project and omitting the use of android:textAppearance in layouts?
What if it were omitted from styles too?
Here's two guides that recommend the use of android:textAppearance:
Styling Views on Android (Without Going Crazy)
TextAppearance allows you to merge two styles for some of the most
commonly modified text attributes. Take a look at all your styles: how
many of them only modify how the text looks? In those cases, you could
instead just modify the TextAppearance.
Best practices for happy Android resources
To ensure consistent-looking TextViews, do not define any of the TextAppearance attributes in a normal style, but always set a TextAppearance from your library on that style’s android:textAppearance field.
Looking at TextView.java, there don't appear to be any attributes that are defined by android:textAppearance that are not able to be set on a TextView directly. So there doesn't appear to be any technical reason that one needs to use them over defining attributes in styles directly, at least in one's ability to configure how a TextView looks.
This means that you can avoid using it in your layouts as well as your styles without any adverse effects, provided that you override all the associated attributes. The base theme defines many different standard android:textAppearances for the various widgets, so you should check that all the widgets are properly overridden.
Based on my experience, android:textAppearance is most useful if you wish your app to appear to integrate into the rest of the device. So if you need big text, you can use android:textAppearance="?android:attr/textAppearanceLarge" and now your text is large! No need to know how many sp that means for the given device/screen size/etc..
However if your app is highly styled and you'd otherwise be overriding all the text sizes anyhow, the value-add of android:textAppearance diminishes. You can certainly use it as referenced in the posts above, but if that doesn't fit into your styling system, then feel free to omit it. It's just another tool to help you get a good-looking app across all devices.
I would also recommend making extra-sure that you try your app across a variety of devices if you choose not to use it, just to make sure that you didn't neglect to override a default android:textAppearance.
Im searching for an android gui-library with more components i could use in my app.
Example:
A microcontroller sends the rpm of a motor (via bluetooth) to my smartphone.
And i want to use my smartphone in order to show the received rpm in progressbar-like element.
But the normal progressbar looks ugly, and i would have to progressbar.setClickable(false); .
As i said before
Im searching a library with more gui-elements(optional: i could modify, customize the outward appearance on my own)
Do anybody of you know about such a library ?
Thanks so far.
If you're just concerned about the external appearance of your GUI elements, I don't think there's any support for different UI elements than the ones provided. However, have you looked into a universal Theme and style for your application?
Here are some excerpts from that document:
A style is a collection of properties that specify the look and format
for a View or window. A style can specify properties such as height,
padding, font color, font size, background color, and much more. A
style is defined in an XML resource that is separate from the XML that
specifies the layout.
A theme is a style applied to an entire Activity or application,
rather than an individual View (as in the example above). When a style
is applied as a theme, every View in the Activity or application will
apply each style property that it supports. For example, you can apply
the same CodeFont style as a theme for an Activity and then all text
inside that Activity will have green monospace font.
Here are some resources which talk about themes:
Mobile Orchard Article
Android Engineer Article
Let me know if that's what you wanted. Themes give you almost infinite possibilities to modify outwards appearance.
When I place things like text boxes they are fixed in one position and I can't move them around easily.
How can I edit the style and maybe put an image at the top of the text boxes and give the app a neat and pretty little layout?
Thanks
Use RelativeLayouts instead of LinearLayouts (i assume that you are using them) which allow free positioning.
To modify the theme/colors, read Applying Styles and Themes.
Create 9-patch graphics and assign them as backgrounds.
I am unsure if this is what you are looking for,but you can arrange the object on the layout from the xml files in res/layouts/ folder.Do not forget to follow the UI guidelines provided by google for android development. Also you can create custom themes for you app if you do not like the default template.
Currently I'm mixing explicit attributes (layout_width, height, alignment) on my various XML layouts with coded styles in styles.xml, plus outsourcing colors from colors.xml.
From your experience, what's the recommended way to organize an android app's layouts?
Usings styles is way more organized and makes the xml code easier to read, I think that the visual editor for layouts sucks, so the best way to edit is still to manual edit text the file. Easier reading is a big plus.
I use style anywhere im repeating layouts, something that is very useful is that any explicits attributes will override those of the style, so you can use styles and if what you need is almost the same, you just explicitly redifine the attribute.
Any time you need to fix a layout issue you can update the style and not need to update it a million times.
On the other hand if you are just using that layout "style" once, there is no reason to write an actual style for it, just do it all explicitly.