Style Editor - dynamically create and apply styles - android

I'm developing an app for text reading. I'm trying to increase the options for my users to customize the appearance of the text and the app itself. Creating multiple styles in my resources folder and switching among them at runtime seems simple enough using the view constructors that take a style parameter.
However I'm also considering going one step further and creating a style editor in my application that allows users to have full control over their experience.
I think that doing this using Android styles is basically out of the question, since the style ids are generated at compile time. I'm considering creating custom views that are light wrappers around the views that I need styled, manipulating the AttributeSet in the view constructor to apply my styles.
How should I dynamically create and apply styles to my views?

your approach is quite right as i tried several posts in several places, if you don't do it yourself, it wont be done :-) Android does not support dynamic theme as it seems.
I wanted mine to be downloadable as a plugin, you need, as you say create a wrapper and be able to extract extra parameters from the AtrributeSet OR add an extra HashTable parameter with the attributes you want to override.

Related

Override a style in Android without modifying layout file

My experience up until now when dealing with styles has been to create a style.xml file and create the properties I want for the style. If I want my style to be based on an existing style, I use the parent attribute. I then specify the style inside of my layout file on the controls that I want to apply the style to.
Where I am at a loss is when I want to use system styles and only update certain properties. I am wondering whether I can leave the layout files alone and not bother applying any styles to the controls. Instead, I would somehow update the property of the system style and that would update everywhere in my app where that style is already being used by default.
More specifically, I want to change the background color of the Actionbar but haven't found a way of doing it other than the way I described above.
You're probably looking for themes, which are collections of styles, applied either globally throughout the application, or for each Activity in particular. Start with this document and investigate further.

Can I edit a style dynamically?

I'm currently developing an app which should be totally customizable by endusers. Imagine the application has many activities with some TextViews, Buttons, etc.
So the client can create a XML file like this one:
<style >
<h1>25dp</h1>
<h2>30dp<h2>
<actionbar>#cecece</actionbar>
</style>
As you can imagine, for example, there are several TextViews which are always "titles" so they should always take this h1 value.
I know I can parse this XML file and for each textview, apply this style manually, but this is not a good way of achieving this because if I had 3000 textViews, I should manually edit them all.
What I want is to "edit" the actual Style programmatically.
Any tip?
You can't access a resource file in the created APK as they are compiled into it. So your idea to "customizable" styles works only in the following scenario:
your app is a library project
your client uses that library project and create a style which extends/overwrites your own style and compile that into a new APK
You are not clearly telling us if the "enduser" is a user of your app/apk or a customer that can do the above mentioned modifications.
An alternative might be to create your own extensions of TextViews, Buttons etc which can load your style set. You need to create your own style language for that and you need to make sure that the custom views understand and apply them.
A lot of work, if you ask me... I would, in general, suggest to make different themes so that the customer can pick the best suited for them...

Android custom gui-components?

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.

How can I make a Android app look pretty?

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.

Consistent UI color in all Android devices

I noticed the UI color (eg Button background/text color) all changes from device to device, based on the current theme that is being used in a device.
What is the best practice to apply custom UI colors for Android app, so that I have same color scheme for my app in all Android devices. I can set text/background color on a UI item. I'm wondering if there is a single place where I can define all the colors which will override the current theme applied on the phone.
thx.
Yes, there is a single place where you can define these values for your app. See Styles and Themes in the Android docs for how it works.
A style is just a mapping of values to predefined names. If you find yourself repeating a number of common attributes in your layouts, you can factor that out into a style. For example, you might have a special button style that defines a specific background and text color.
A theme is a sort of meta-style. It can be applied to an Activity or even a whole application through your AndroidManifest.xml. Among other things it defines the default styles for widgets and values that control other parts of the look and feel for your UI.
When you're trying to blend in with the system in an otherwise custom UI for your app, you can query the current theme for values. Just like you use the # reference syntax #android:drawable/foo when referring to a system resource, you can use the syntax ?android:attr/foo when you want to use the value stored in the system theme attribute foo.
In your case, if you want to change the primary text color across your app, apply a custom theme that sets the attribute textColorPrimary. If you just want to be sure that an element of your app is using the primary text color as defined by the device your app is running on, you can set android:textColor="?android:attr/textColorPrimary". The same principles apply elsewhere as well.
If you want to see what attributes are used in the system, they are defined as part of the Android framework in this file: frameworks/base/core/res/res/values/attrs.xml. Look at the children of the XML element <declare-styleable name="Theme"> at the top. To see examples of what the system sets these to, see themes.xml in the same directory. Finally, not all of these attributes are public - non-public attributes cannot be set by an app, they're implementation details of the Android framework. See public.xml for the complete list of which attributes are available for use in apps.
Best practice is to apply a custom theme to your application, and override as much of the default properties as you need.
Almost everything can be changed, except
The Menu
Some properties of AlertDialog (these can be changed using a custom dialog)
OS provided views such as the Quick Search Bar (QSB)
If you like the look of the default SDK resources then you can find these in sdk_folder/platforms/android-9/data/res/ (replace 9 with the SDK version you want the resources from) - copy the ones you want into your App and reference those.
You can take a look at the theme the SDK uses:
themes.xml
styles.xml

Categories

Resources