I have listView with thumbnails. Some of list items should be disabled. So, I would like to create a style to referenced from code, when user is logged in then these items are enabled.
How to name/place drawable resources?
/res/drawable/item1_enable
/res/drawable/item1_disable
/res/drawable/item2_enable
/res/drawable/item2_disable
It is not very nice way when there are more drawables which could be disabled. Is there a way to place it to structure based on style? EDIT: Is there any way how to group resources by style? What is prefered way to do.
/res/drawable/item1
/res/drawable/item2
/res/drawable-styleDisable/item1
/res/drawable-styleDisable/item2
/res/drawable-styleEnable/item1
/res/drawable-styleEnable/item2
My second related question is: https://stackoverflow.com/questions/25933441/android-structured-styles-selector
Related
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...
A style defined in XML resources cannot be "applied" at runtime.
So, given a style name, I would like to read the style items one by one, interpret them and apply them programmatically to selected widgets.
Because sometimes, a user may want to change the style of some widgets at runtime an I want that style to be exactly as the one defined in the resources.
The only reason I want to do it this way is to preserve consistency between the style defined in the XML resource and the style I appply at runtime.
How can I read the style items? I know one way: to parse the XML file myself, but maybe there are some built in methods to directly read the style I am not aware of.
I'm looking at how to give an app that I develop and deploy it's own look and feel. So I read about the Style and Themes on developer.android.com. After some initial success with text color, text size, background color... I seem to get stuck at changing buttons, toggle buttons... It appears to me that to change the color of a button a .9.png file must be created (possibly for the different dpi's). Looking at the artwork in the default style, I see a large number of these .9.png files. To have a consistent style they should all be updated.
Is it correct to say that defining a new style involves modifying/recreating the .9.png files?
If no, how should one go about modifying the style of these .9.png based elements?
If so, are there any tools that assist with creating a custom style? And are there any style packages that can be downloaded/purchased?
I'm not sure it's a good idea to give a new look to every UI control in your application unless you are a very experienced designer. Probably, we can't beat Google designers at their craft and it would be better to comply with existing styles adding some cool features instead of changing button colors at random.
I've created my own custom preference objects that extend Preference. I've only created them because there are no Preferences for these custom data types.
Everything is working, but my custom preferences don't have the same appearance because they are missing the horizontal divider that the system preference objects have. I've looked for the code that is creating the horizontal divider, but I can't find where it is done.
The built in divider isn't just a thin bar. There is a bit of a gradient to it. I'm thinking that this may be in a layout file, but I can't find the layouts for the system preferences.
Anybody got an idea how this is implemented?
Very old post, but to those who stumble upon this. Wasn't sure if the OP was asking how to change the divider or where the divider images come from. So I'll address both.
How
Preferences uses a ListView for populating all the individual preferences. That means you can change the divider by using the .setDivider() method from ListView. A PreferenceActivity will already have the getListView() method for you. However for PreferenceFragments just use the android.R.id.list ID to find it.
If you don't want to change the divider through code, you can always use a theme by overriding the listDivider attribute. Eg:
<item name="android:listDivider">#drawable/custom_divider</item>
Note, that will change the divider for EVERY ListView in your app.
Where
The listDivider drawable used depends on what Android theme is activated. You'll find all these images in the installed Android SDK at this location:
[Android SDK]/platforms/[API]/data/res/drawable-[DPI]/
Just do a search for `*divider_horizontal*`, and you'll turn up quite a few. They are nine-patched and not all of them are solid colors.
I want to develop an android application, but i dont want to use the default controls(buttons, checkboxes, radio buttons, etc.,). Is there any way to customize those controls to make it appear nicer. If so some tutorial or guide will help me a lot. Thanks....
If you want to create completely new UI elements, you should read the developer guide topic on creating custom components/views.
If, on the other hand, you simply want to change the appearance of existing UI elements, below is a non-exhaustive list of things you'll need to do. This assumes you're familiar with the Android resources framework and layout system.
First, see how these are implemented in the Android source code (AOSP, GitHub's mirror). All of the code you're interested in is in the frameworks/base.git project (quick links: resources, Java sources)
For each type of UI element, create Nine Patch PNG drawables for each of the UI states (default, disabled, pressed, focused, etc.) and for each relevant density (e.g. medium, high , and extra-high densities). These PNGs should be in your res/drawable-mdpi/, res/drawable-hdpi/, and res/drawable-xhdpi/ directories.
For each type of UI element, create a state list XML drawable (<selector>), which will be in your res/drawable/ directory. The state list drawable for the default Android push button can be found here.
Set your button/textbox/etc.'s android:background attribute to the state list drawable name. For example, the attribute value should be #drawable/mybutton if your state list drawable is res/drawable/mybutton.xml. Note: You can use themes to reduce redundancy (i.e. keep them DRY) in your XML files.