Android Tabhost Problem - .setIndicator - android

First let me clarify that i have already referred the SO question related to "Android - TAbhost".
I have done googling about "Android Tabhost" but failed to find the solution.
My problem is:
If are having <3 tabs then it is fine.
but
Supporse if we are having 4 tabs with indicator title as TabHost1, TabHost2, TabHost3, TabHost4). But this title in Tab does not get fitted with tab. so is there any way to fit the Title Text (i.e. indicator) inside the tab ??

I thought the source of our issue was somewhere in the framework's code. And sure enough, I found some clues :
First, if you look inside the TabWidget code, you will see that the label you set in setIndicator is passed to an inner class called LabelIndicatorStrategy which will take care of inflating the view associated to the top part of the tab. This inflation is done using an xml file tab_indicator.xml. This layout is based on a RelativeLayout containing an ImageView and a TextView. And if you look at the properties of the textview, you will see that it refers to a style in android styles.xml. And here finally, you realize that we have THAT :
<item name="ellipsize">marquee</item>
<item name="singleLine">true</item>
So, now, 2 options :
First, override the style by creating your own style, which in my opinion would be the really painless way and then change these properties to something that suits you better. Though the result might not be very nice. this will require some testing.
Or, put on your gloves and copy the code from the TabWidget class, because another issue here is that the inner class I mentionned is... PRIVATE so, no inheritance possible if I'm not mistaken... SO I think, much much more pain than the styles.xml's way.
Hope this will inspire you, keep me posted of what you get please. I'm still interested.

i have solved the above issue by decreasing the size of Font, check the below code of Style.xml:
<resources>
<style name="MyTheme" parent="#android:style/Theme.Light">
<item name="android:tabWidgetStyle">#style/LightTabWidget</item>
</style>
<style name="LightTabWidget" parent="#android:style/Widget.TabWidget">
<item name="android:textSize">12px</item>
<item name="android:textColor">#1E90FF</item>
</style>
</resources>

Related

ViewPageIndicator Tabs - How to achieve the following style?

I'm using ViewPageIndicator to customize the looks of the tabs in my app but I'm really new to android so I don't really know to get exactly where I want to.
Here's a gif that I made to show how I want it to behave: http://i.imgur.com/1FSw5ae.gif
I couldnt find any options to make the make the background semi-transparent like android:background_alpha or something , instead I found this topic How to make a background 20% transparent on Android but it didn't worked either.
As for the tabs switching color depending on the content I have no idea how to get there =/
If anyone could help I'd be really glad.
Here's the code for the styles:
<style name="CustomTabPageIndicator" parent="Widget.TabPageIndicator">
<item name="android:textSize">16sp</item>
<item name="android:textColor">#6abd45</item>
<item name="android:background">#80000000</item>
</style>
Thanks in advance.

Android custom titlebar style/theme

I created an activity with a custom titlebar and a button in it, which is extended by all other activites. It works well so far, but when I use an activity whith theme.dialog the titlebar is not shown correct. There is a padding to the left and right of the title and height is limited to 25, I guess.
So I tried the same to the theme.dialog windowTitleSize as I did to the theme. But it showed the same result as if I just change only the title of the normal theme - a padding to the left and right and the wrong height.
After a lot of googling I found at least one solution that works here on stackoverflow. Unfortunately it fixes the padding for the titlebar at runtime with Class.forName() and getField(). I could change the height of the titlebar with layoutParams the same way, but would like to set it all up in xml.
I browsed themes.xml in the ..data/res/values but could not find where the limitation of the layout is set. Finally I tried to extend the normal theme and create a dialog myself. That brought me to Widget.PreferenceFrameLayout and the following errors in my xmls:
In styles.xml "no resource found..." on all "...android:border..."
<style name="MyPreference">
<item name="android:borderTop">20dp</item>
...
</style>
And in themes.xml "no resource found...android:preferenceFrameLayoutStyle"
<style name="MyThemeDialog" parent="android:Theme">
...
<item name="android:preferenceFrameLayoutStyle">#style/MyPreference</item>
...
</style>
How am I supposed to use the given themes and styles the right way to set up the titlebar in theme.dialog?
-----edit-----
I recognized, that the mentioned attributs are not available in the attrs.xml of api8, so sorry for the hasted asked question. Sometimes I just can't see the forest because of all the trees.
Thanks in advance for your help,
Christel

Android - Make a custom titlebar that uses the device's current titlebar theme

I'm trying to make a custom titlebar for my first Android application.
While I can find lots on the web about how to make them so you can change colours etc, I want my titlebar to look the same as the "standard" titlebar, but with a button that I can configure. This means copying the device's currently active themes to be able to style it in exactly the same way.
Not all devices simply use a gradient in the titlebar style, so adding a gradient (as suggested in other SO questions) doesn't really make sense.
Does anyone have any pointers how to read the style information?
try to extend an existing theme e.g.
create your own style which can ofcourse extend from existing from an existing theme. change the windowNoTitle to true.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="noTitleBarStyle" parent="android:Theme.Black">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#color/darkGrey</item>
<item name="android:colorForeground">#ff3333</item>
</style></resources>
or try to do it runtime as discussed here
Android - change custom title view at run time
I hope this helps.

Android style descriptions

I tried changing the appearance of a spinner and I partly succeeded. I'm doing this via overriding parts of the theme. I managed to change the text size of the spinner item (i.e. the text size in the drop down button) with my themes.xml and styles.xml:
My themes.xml file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomTheme" parent="#android:Theme.Holo.Light">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:spinnerItemStyle">#style/CustomSpinnerItem</item>
</style>
</resources>
My styles.xml file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomSpinnerItem" parent="#android:Widget.TextView.SpinnerItem">
<item name="android:textAppearance">#style/CustomTextAppearance</item>
</style>
<style name="CustomTextAppearance">
<item name="android:textSize">30dp</item>
</style>
</resources>
However I cannot find the attributes that are responsible for the text appearance of the items in the dropdown list of the spinner. I tried dropDownItemStyle amongst other things. In my opinion the attribute names are not self-explanatory, so I wanted to know whether there is a documentation of what attribute does what in a style to find out which attributes to override. I found it very cumbersome to trace back all the styles used in a theme via the themes.xml and styles.xml of the platfrom and then try to find the right attributes via trial and error.
I know that one can change the appearance by passing layouts to the adapter, however, this is not really what I was looking for, since (as far as I know), you can only use inheritance in styles and not in layout xml files. If I created a custom layout for the adapter I'd have to create 9-patch images etc., which I think is a bit too time consuming in case I only want to change the text size.
Of course it's possible that I misunderstood the whole concept, since I'm new to Android ;)
You probably have found out the answer since you asked but for others looking at similar questions:
I do not know of a list of attribute names with good explanation of what they do (R.attr's page mostly gives information that is already in the name) but the way I do it is:
Start from the element I give to setDropDownViewResource(), in my case: android.R.layout.simple_spinner_dropdown_item and find.
Find its layout definition in \sdk\platforms\android-17 (specific platform version to avoid redundant results).
Get its style from the layout file. In this case: ?android:attr/spinnerDropDownItemStyle
We now have the attribute name we need.
It's better to do it that way rather than try to guess what attribute to use because you know which attribute the system itself use so it's very likely to be the correct one (unless there's a bug).
If I created a custom layout for the adapter I'd have to create
9-patch images etc.
Well, no, the layout determines what kind of GUI element you would have (a textfield, a spinner, an imagebutton, a custom element...), not how they are styled (nine-patch backgrounds, text colors...), so you still would have to mess with styles to get the right appearance.
For example, for visual consistency I ported the button, checkbox and spinner style from Theme.Holo to Gingerbread, yet I did not mess with layout, all I did was the aforementioned steps plus looking up the result (spinnerDropDownItemStyle in the above example) in themes.xml, which gave me the style name (e.g.: Widget.Holo.DropDownItem.Spinner).
Then I looked that up in styles.xml and imported it (and any parent*) in my project's styles.xml, searching and copying any Holo specific reference in my project and adjusting the namespace accordingly (add android: to attributes and replace ?android:attr with #style for what I copy to my styles.xml file).
So far I haven't had to mess with layouts at all (even the presence of radio buttons in spinner dialogs on Gingerbread is determined by an xml attribute: android:checkMark).
If a style has no parent attribute (like Widget.Holo.DropDownItem.Spinner) then its parent is the same style minus the last element (e.g.: Widget.Holo.DropDownItem)

Android Custom PopupWindow/Dialog

I'm trying to get a completely custom Dialog or PopupWindow, without any of the default Android UI controls (title, background, buttons, whatever).
Is this possible at all? I've spent hours searching for this, but no luck... It seems like this should be easily possible, but I can't find it.
Preferably this would be by inflating a View from XML, but at this point anything that would just work would be nice.
Thanks.
Steps I took:
Create a class extending Dialog.
In the onCreate, call setContentView(x, y) with x being your R.layout and y being R.style.popupStyle (see below).
In your res/values/style.xml, you need to override the default DialogWindow style. I tried just making a style that has this one as its parent, but that still didn't clear all defaults. So I checked the Android git tree and got the default style, and just copy-pasted it. This is the one:
<style name="Theme.Dialog">
<item name="android:windowFrame">#null</item>
<item name="android:windowTitleStyle">#android:style/DialogWindowTitle</item>
<item name="android:windowBackground">#android:drawable/panel_background</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
</style>
You'll get a few errors, just solve them by copying more stuff from the official Android styles.xml and themes.xml files. Here's the contents of my styles.xml file: http://pastebin.com/RRR15YYS
That just gives you a white popup, no borders, nothing. Start customizing. :)
Thanks to mbaird for putting me on the right track.
[edit] I needed to look up my own answer again, and I spent at least ten minutes searching the official android styles/themes files, so here they are, for future reference:
styles.xml and themes.xml.
It sounds like you are trying to really customize an AlertDialog. For what you are wanting to do you may be better off just creating your own class that extends Dialog, similar to how you create activities by writing a class that extends Activity.
You can set the layout XML by calling setContentView() inside the onCreate() method of your custom Dialog class, just like you would in an Activity.
I've run into limitations on how much you can customize AlertDialogs in the past, and I've just implemented my own Dialog classes to get the level of customization that I needed.

Categories

Resources