I want to change the padding on the textview in the TabLayout. I have a tab that's called Subcategories. This is breaking line wrapping into two lines. Is there a way to do this?
There are answers only concerning the old TabHost view, I am using the TabLayout used by Google's Material Design library using android.support.design.widget.TabLayout.
For TabHost: How to add padding to a tabs label?
The TextView is not padded out, but the layout surrounding the textview is, so change the LinearLayout's padding:
int tabIndex = 0;
LinearLayout layout = ((LinearLayout)((LinearLayout)mTabLayout.getChildAt(0)).getChildAt(tabIndex));
layout.setPadding(0, 0, 0, 0);
Related
I am using tabhost. I have two tabs in that. I can able to set border for tabwidget. But I don't know how to set border for each tab.
I tried to get current tab and convert the view as textview and had
set border but It was looking like view is wrapped,so the border
encloses the tab name with no gap .I don't know how to add padding
to make it as match_parent.
Here is my code,
int tab = TabHostWindow.getCurrentTab();
TextView tv1 = (TextView) TabHostWindow.getTabWidget().getChildAt(tab).findViewById(android.R.id.title);
tv1.setTextColor(Color.WHITE);
tv1.setBackgroundDrawable(getResources().getDrawable(R.drawable.tabdes));
Guide me please, Thanks in advance.
I'm using a table layout to arrange some buttons. As long as I use the same font for all the labels they are properly aligned in each row.
For some buttons I'd like to use icons from a custom ttf font.
When I use such an icon, the button is placed slightly higher, like so:
(This image is scaled up to make the the problem more evident.)
I took measurements - the buttons appear to be of same height, regardless of the used font.
Why are the buttons not aligned properly?
Does anyone have a suggestion to get them aligned?
Thanks.
Following CommonsWare's advice (thanks for the quick replies!), I tried this:
final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.gravity = Gravity.CENTER_VERTICAL;
row.setLayoutParams(layoutParams);
This did not work. Will try the base alignment comment next.
Add the following attribute to your TableRow:
android:baselineAligned="false"
By default, the button labels' base lines are vertically aligned which causes the offset you experience.
I have two relative layout say relative layout1 & 2 having an edit text and a button. In order to provide spacing in between I specified margin top of 30dp to relative layout2. Another relative layout 3 is generated dynamically in between them when we click button of the relative layout1. If so I have to remove margin top of relative layout2 programatically.
snapshot is like below
In this case a provide padding in xml. But when another layout is added in between like this
the padding is not preferable. I have to remove padding programmatically. How can i do that by checking whether there is a layout in between and remove that padding. I am a beginner in android coding....
You can set margins, or anything else regarding a layout like this:
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)relativeLayout.getLayoutParams();
layoutParams.setMargins(80, 0, 0, 0); // left, top, right, bottom
relativeLayout.setLayoutParams(layoutParams);
You can find more Information on LayoutParams here:
http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html
If you want to remove padding call
relativeLayout.setPadding(0,0,0,0);
I'm using this library for pagerSlidingTabStrip Component. I have TabStrip which occupies full screen in Portrait Orientation. But In Landscape it doesn't occupy full screen.
I'm using app1:paddingLeftRight attribute in tabstrip tag in xml, but it is not working for me. I want to setPadding programmatically for each and every device both in landscape and portrait mode. So I will place the Tabs items equally.
Any Help greatly appreciated...........
Thanks in advance
Try do this in updateTabStyles() in class PagerSlidingTabStrip in library. Something like tab.setPadding(left, top, right, bottom).
This thread might be old, however I found a solution for this. For those who are looking (still) for solution try this :
tabs.setViewPager(pager);
/*
Add top and bottom padding
*/
LinearLayout parent = (LinearLayout)tabs.getChildAt(0);
int padding = 20;
for (int i = 0; i < parent.getChildCount(); i++) {
View tab = parent.getChildAt(i);
tab.setPadding(tab.getPaddingLeft(), padding tab.getPaddingRight(), padding);
}
Put this code after setting your viewpager, or else it will read parent with 0 children.
Cheers, Happy coding.
divider in tabWidget is working fine but when background of tab widget is set like
tabHost.getTabWidget().getChildTabViewAt(tabId).setBackgroundResource(R.drawable.tab_indicator);
problem is how to set divider in tab widget after setting background
though i used
tabhost.getTabWidget().setDividerDrawable(R.drawable.tab_widget_divider);
is does not work for multiple tab.
There may be multiple reasons for the dividers not showing up...
1. setDividerDrawable() must be used before you add the tabs to the tabHost to work.
2. By default there's are -2(left), -2(right) margins set to each tabindicator's View...
By default the system is using 9-patch drawables for tabWidget backgrounds with at least 2 pixels left transparent(or semi-transparent for shadow-effect) to the left and the right side.
1. demonstration
2. Stock 9-path drawables for tab widget background. You can use these for experimenting
If you don't wan't to use 9-path drawables...
you can set the margins to 0 to prevent the tab views overlapping your divider. Here's the code:
View v;
int count = tw.getTabCount();
for (int i = 0; i < count; i++) {
v = tw.getChildTabViewAt(i);
v.setBackgroundResource(R.drawable.bg_tab);
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
params.setMargins(0, 0, 0, 0);
}