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);
}
Related
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);
I have 4 tabs currently and they are all the same width. I would like the last tab to be less wide than the others. I tried using LayoutParams to specify the width but this didn't seem to work.
TextView view = new TextView(this);
view.setText("Hello");
LayoutParams lp = new LinearLayout.LayoutParams(10,10);
view.setLayoutParams(lp);
actionBar.addTab(actionBar.newTab().setCustomView(view).setTabListener(this));
This is what it currently looks like
I want the fourth tab to be an overflow button. Something like the image is what I'm going for. If there was a way to have only 3 tabs and then an overflow button at the edge that would be perfect.
It will be possible using fragments.
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.
I am creating TextViews in LinearLayout programmatically and I would like to separate them with a divider (just a simple line). I have googled endlessly, what I have found is that I can use .setDividerDrawable, but I don't want to use external images for this.
Any tips?
How to Add Divider to an Android Layout Programmatically
Create a View 1 or 2 pixels tall and width match_parent and set the background color to whatever color you want the divider to be.
Separate the divider from the items above and below with margin settings.
Example:
ImageView divider = new ImageView(this);
LinearLayout.LayoutParams lp =
new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
lp.setMargins(left, top, right, bottom);
divider.setLayoutParams(lp);
divider.setBackgroundColor(Color.WHITE);
You could use a simple drawable in xml for the divider (example here), or use a 9-patch image which barely takes anything.
Then, use the LinearLayoutICS in order to show the divider on most of the devices. you can check out this post i've made about it.
For linear layout you can use this attribute to set divider android:divider="some color"
android:showDividers="middle"
I want my application to have button bar at the bottom, that is similar to this one (Motorola Defy+):
How can this be achieved? I've tried ButtonBar style with regular buttons in it, but they always have margin in this case.
By code:
Make the bar LinearLayout horizontal. Let´s say its name in code will be bbll.
LinearLayout.LayoutParams params = bbll.LayoutParams();
params.leftMargin=0;
params.rightMargin=0;
... or params.setMargins(0, 0, 0, 0);
bbll.setLayoutParams(params);
By layout simply set each margin to 0. That's all. If you have done it and it won't work, put the code here, please.
But you should set bbll.setPadding(0,0,0,0) , too. Or you'll see empty space between the bar (that is invisible) and the buttons. aqs has a good thought.