I like the title bar style from the Android preference category.
In my Activity (not a PreferenceActivity) How can I use the same style?
Since I just spent the last few hours trying to answer this old question, I'll do it here for anyone else.
It turns out the resource the preference category style is using is listSeparatorTextViewStyle.
You use it like this:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello, World"
style="?android:attr/listSeparatorTextViewStyle"/>
Using style="?android:attr/preferenceCategoryStyle" didn't work.
The main layout is most likely a ScrollView with a LinearLayout. As for the individual layout, I believe (just guessing after looking at the documentation) that you can use the various attributes in android.R.attr - look here: http://developer.android.com/reference/android/R.attr.html. There are attributes like preferenceCategoryStyle, preferenceStyle, etc. You can apply any style to any of your views.
Related
So I would like to see my layout preview with the fields filled with something like default placeholders but if I use bindings the settext attribute is already used and the fields are showing empty since there is no info from the models yet.
<TextView
android:id="#+id/tv_user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:gravity="center"
**android:text="#{showBlueportSpotViewModel.name}"**
android:textAllCaps="true"
android:textSize="20sp"
android:textStyle="bold"/>
I tried this:
android:text="#{showBlueportSpotViewModel.name ?? #string/blueport_placeholder_name}"
but I still see the view empty.
Do you guys any workaround? I guess once a workaround is found, it can be used to ImageView and src for example and etc..
Thank you!
You can use the tools attribute to define properties that will appear in the layout preview but will not appear when you run the app.
Add the following to your root view:
xmlns:tools="http://schemas.android.com/tools"
Then use the tools attribute to define text that will only appear in the layout preview:
tools:text="placeholder text"
The tools attribute is very useful when mocking up views in the editor. All of the tools attributes are stripped when the app is packaged. More information here: http://tools.android.com/tech-docs/tools-attributes
I found a workaround
I added
xmlns:bind="http://schemas.android.com/apk/res/android"
to the layout
and just having duplicated declarations in the view like:
android:text="#string/blueport_placeholder_name"
bind:text="#{showBlueportSpotViewModel.name}"
or
android:src="#{showBlueportSpotViewModel.blueportImageDrawable}"
bind:src="#drawable/android_menu_header"
I don't really know if this has secondary wrong consequences so I won't accept this answer until somebody can comment and say if it is okay.. Thanks!
Say I have a button defined in XML roughly as follows, embedded in layout/activity.xml:
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/a_button"
android:background="#drawable/a_unique_drawable"/>
Separately I have defined drawable/a_unique_drawable.xml. Is it possible to define the drawable in line with the button? Given that the drawable is unique to the particular button and used in no other places I believe it could improve clarity to have everything defined together. I'm looking for something roughly like:
<Button ...>
<android:background>{contents of drawable XML}</android:background>
</Button>
I could also be convinced this is a terrible idea but I'm nevertheless curious if it's possible.
No it is not possible. In addition to that, you can define more options as resources, styles, themes - so why to make an inline coding?
I have an android app that has been working fine pre-Android 5.0. With the update, I noticed that checkboxes and radiobuttons placed on white backgrounds are not visible if they are not selected. For example, this is what a checkbox looks selected and unselected in jellybean:
As you can see, there is a light gray square when the checkbox is not selected. However, after updating to lollipop, this is what it looks like:
So, as you can see, there is no gray square or anything that suggests there is a checkbox here. The same problem happens with radiobuttons. I really don't want to go trough the pain of creating new drawables just for this simple ting. I have seen that checkboxes within the accessibility menu of android 5 have a nice square, but haven't figured out how to make mine look the same:
I tried creating a new android project and just adding some checkboxes and radio buttons with a white background, but they are still invisible when unchecked. I'm using xamarin studio and c#, if that makes any difference. Anyway, I'll understand any java code you post.
This is what my checkbox code looks like:
<CheckBox
android:layout_width="wrap_content"
android:layout_height="0dp"
android:id="#+id/chkSeleccionar"
android:layout_gravity="right"
android:gravity="center_vertical"
android:clickable="false"
android:focusable="false"
android:scaleX="1.5"
android:scaleY="1.3"
android:layout_weight="50"
/>
I couldn't get the theme working, but what did work for me was the following:
android:button="#drawable/abc_btn_check_material"
android:buttonTint="#color/red"
Put this into your CheckBox XML layout.
Just change the
android:buttonTint="YOUR COLOR"
It works.
Make sure you are using a Material theme for Android 5.0 devices - this will ensure you're styling remains consistent with other components. Look for an android:theme element in your AndroidManifest.xml file (either on your application or on an individual activity), then look up what style is set there and check the parent attribute for the style.
Add this attribute
android:buttonTint="#EEEEEE"
The button has is set in the activity's XML layout with:
<Button
android:id="#+id/dummy_button"
style="?buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/dummy_button" />
The part to pay attention to is style="?buttonBarButtonStyle". The definition for the queried style is defined in styles.xml as:
<style name="ButtonBarButton" />
The style doesn't actually set any values for the button and so I can't understand why I would change anything about the button and the way it displays.
When the button is set to use the empty style, it looks like this:
But when the line style="?buttonBarButtonStyle" is removed, it looks like a standard button like this:
At first I thought that assigning the empty style would replace the default style settings for a button, but trying this in my own app doesn't change the appearance of a button at all (as I would have expected an empty style to do).
Can anybody work out exactly why this empty style is changing the look? To replicate this yourself you can create a new app using the "Fullscreen Activity".
Your ButtonBarButton and buttonBarButtonStyle has no relation to each other. You apply buttonBarButtonStyle style which is a theme attribute and defines some style for a bar button. If you can to apply your custom empty style to a button use:
style="#style/ButtonBarButton"
I'm not sure what it is that is surprising to you. The usual look of buttons is the one in the second image, so when the style is applied, that inside rectangle is removed which is a custom look. If you have seen buttons without any custom styling you would have seen that they look like the one in the second image.
After taking a look at theming for Fede's UberMusic I came across the file album_screen.xml. Below is the source of that file. Basically I noticed that his themes have the ability to use custom views that are a part of his application, and that they have this XML namespace at the top theme. I am missing the connection as to how he is able to apply his attributes to views that he does not control, and how Eclipse will compile the cod below without fail. I placed the URL http://schemas.uberdroidstudio.com/theme into my browser's address bar but nothing came up, and I cannot figure out where/ how Eclipse knows the attributes that the namespace supports. Thank you ahead of time for your help.
<?xml version="1.0" encoding="utf-8"?>
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:theme="http://schemas.uberdroidstudio.com/theme">
<TextView
android:id="#id/artist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.0"
theme:textFilter="uppercase" /> <!-- This is the interesting line -->
I suspect that the theme:textFilter="uppercase" line isn't actually having an effect on the (apparently vanilla) TextView.
As for the URL of the namespace, it is interesting that you can't access it, since it does not appear to be a local styleable (Android would have you refer to a local styleable namespace as http://schemas.android.com/apk/res/your.package). +1 for novelty.
The solution is actually not as complicated as I originally thought. XML namespaces are arbitrary strings that just need to be unique. If your namespace does not start with http://schemas.android.com/apk/res then it is not validated and the APK package is not checked for declare-styleable or the like.
Now a custom namespace if very simple to implement, as illustrated by this code snippet in GitHub. Finally, applying custom XML attributes to "normal" widgets can be accomplished by using the LayoutInflater.Factory and calling setFactory before you inflate your views. Throw it all together and you have a highly theme-able, XML driven application like Fede's UberMusic.