Simple aim:
To have default buttons in the navigation bar of my ActionBar with the text centre aligned. I simply want to use the default, simple way of:
ActionBar.Tab myTab = Actionbar.newTab()
myTab.setText("my tab's text");
What's the problem
I cannot find any simple way to do this whatsoever. You can't access the views (as ActionBar.Tab.getCustomView() always returns null due to it being the default view). There is no method that I can see in ActionBar, ActionBar.Tab, etc to get the current view, get or modify LayoutParams (especially Gravity). A visualisation of the problem is below (one line seems to work right, but double lined navigation buttoms definitely seem left aligned):
Unideal solution
Am I right in negatively thinking that the only way to accomplish this is to use custom views for all of my tabs, somehow guess / attempt to copy the default formatting for the tabs (as I can't find anyway to access these views) and assume / hope that the default formatting / font / style of ActionBar.Tab's text does not change any time soon?
Surely there has to be a better way?
AFAIK, there's no way you can access the Views in ActionBar. Using custom layout seems the only solution. However, doesn't Android align the text to center automatically? It apparently does so in all my applications.
please download the follwing example. it will help you. i am sure i take help from this demo.
https://github.com/JakeWharton/ActionBarSherlock
Related
How can I move a text box to the right or left in Android?
I want to make something like this:
I currently just used space to move it to the right but obviously this only works in a resolution that I was working on.
You can use
android:gravity="right"
You can also use left, end, start, centre, etcetera.
You can view the docs here
In this case you may also want to use:
android:width="fill_parent"
you can handle this on the xml side of things
Probably want to use a RelativeLayout with layout_alignParentLeft and layout_alignParentRight:
see : Aligning textviews on the left and right edges in Android layout which should be a pretty good example for you
In this video Google mentions using windowOverscan in the styles file. The problem is I do not have a styles file in my Android Wear module. Is there a more recent method that allows you to center text properly?
I found out through experimenting that the windowOverscan attribute is set within the style you choose in your AndroidManifest file. I was able to view the settings of each style by going to the Design tab in the layout xml then finding the style attribute and clicking the three dots and then going to the System tab. When a style is selected you can see the code at the bottom of the window.
I also read that windowOverscan is set to true by default.
My problem was actually caused by the custom font I was using and not windowOverscan. Hope this saves someone the trouble.
I would like to see visually how much space each box takes with as little effort/changes to the code as possible.
I would like to know if it's possible to just put a line around the outer margins of the View or ViewGroup object.
Since it's just for debugging and styling I would like to also quickly turn it off, so I do rather make the changes to my code in one place so it's easy and quick to undo. Is this a default option I am missing? Somehow I expect this feature to exist already.
Here someone asks a different but slightly related question with not a nice answer for my case.
Here someone gives an answer on how to outline one View.
Border for an Image view in Android?
Code-wise you could follow the answer to the first link you posted and create a drawable with the name "developer_borders" or something similar and apply it to every view you wish to have its borders visible.
To easily remove it afterwards, you can right-click the directory of your project and click Replace in Path.... For Text to find you want to search for android:background="#drawable/developer_borders and for Replace with don't use anything. This will find every occurrence of what you are searching and replace it with an empty string.
There might be an easier option. Some devices have quite powerful Developer Options. "Show layout bounds" is what you want but take a look at the rest while you are at it, some are pretty awesome.
i have a couple of questions about activity's
i have a activity which i want to create some options for it. for eg. i want the user to be able to change the font size of text views.
i am a noob in java and eclipse. first i thought i can change the xml values via java but then i found out that i can't and they are read only.
so what is the best solution for creating options which are visual like changing colors and font sizes and picture through entire project?
for eg. i have 10 activities and inside each activity i have some text views. i want to change all of the font sizes. in xml you can create a dimen and all of the text views with android:fontSize:"#dimen/example will have the same size. but in java it takes more code and time.
what should i do ? couple of examples would be nice
thanks in advance
so what is the best solution for creating options which are visual
like changing colors and font sizes and picture through entire
project?
Have a look at the setTextSize() method of the TextView class. This will let you set the size of the text programatically.
setTextColor() will let you change the color.
setTypeFace() will let you change the font.
Having said that about TextView, it applies to all the subclasses of TextView like Button, EditText, etc.
i have a activity which i want to create some options for it.
I suggest you create a singleton instance that encapsulates all the information to change the visuals of your activities like text size, typeface, etc. This instance should then be shared among all of your Activitys.
couple of examples would be nice
No, an SSCCE would be nice. We need to see what you have tried. Code or you didn't do prior research.
I had design 5 tabs using Swing. Each tab contains 2 or 3 sub tabs. Now the problem is, at run time the text fields in tabs are overlapping. I use the method
refreshI18NText(jPanelReceivedForm1A)
to refresh the jpanel.
but still I'm getting the problem.
You need to make sure you are using the correct layout manager. The Oracle tutorial is useful for selecting and explaining each layout manager.
http://download.oracle.com/javase/tutorial/uiswing/layout/using.html