How top set tab icon and label in FragmentTabHost - android

I am using FragmentTabHost to implement bottom tabs with icon and label but following sentence shows only label
mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple",getResources().getDrawable(R.drawable.ic_launcher)),
Fragment1.class, b);
I also see somewhere following works properly
setIndicator(View);
but I don't know syntax to set custom view in setIndicator
plz help
Thanks...

I make custom view and set it as setIndicator(View v);
View chatView=LayoutInflater.from(this).inflate(R.layout.chat_icon,null);
mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator(chatView),
Fragment1.class, b);

Related

How to set border of each tab in tabhost

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.

Create Custom Action tab bar

I am trying to create a custom tabbar using this tutorial for android 2.3.3 and above,but the title bar is disabled(Refer the image attached app deployed on Android 2.3.3 ).
Also, how do I customize the titlebar. Please guide me for the same.
I had a similar problem. I solved it this way. Created new layout for action bar tab's title and initialized first tab like this:
// init first tab indicator
View viewTabMain = getLayoutInflater().inflate(R.layout.your_title_layout, null);
((ImageView) viewTabMain.findViewById(R.id.imgTab)).setImageResource(R.drawable.icon_1);
// add main tab
tabHost.addTab(tabHost.newTabSpec(TAB_MAIN).setIndicator(viewTabMain).setContent(new TabHost.TabContentFactory() {
#Override
public View createTabContent(String s) {
View view = new View(getApplicationContext());
return view;
}
}));
To other tab (or tabs) use the same. I hope this will help you!

ActionBar custom layout like ICS edit contact

I just started playing with the new support library with ActionBar support. I'm trying to implement a bar that looks basically identical to the Ice Cream Sandwich layout on the edit contact screen. I understand I probably need to implement a custom view something similar to this - How to display custom view in ActionBar?. What I don't understand is exactly what that view is, and the best way to implement it.
Here's the screenshot of what I want in my actionbar:
Is that just a view with an image and some text, or a styled button, or something totally different? It has some state pressed properties.
Thanks for the help.
You can try using a custom view, by adding the following code when you want the button to appear :
// Inflate the view from XML file
LayoutInflater inflator = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.search, null);
// Tell the view to occupy the whole actionBar view (MATCH_PARENT)
LayoutParams layout = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
getActionBar().setCustomView(v, layout);

Android:Robotium: Tab click with only icon

I have tab layout.That has only icons not text.I tried with clickOnImageButton and ClickOnButton clickOnImage and also pressOnMenuItem(R.drwable.icon)but not worked.How can i do this with solo?
Note: Image View present at the top of the tab.(tab is at bottom)
Tabhosts are evil. Luckily i also have had to automate them and so know the answer.
what you do is you have to get the tab bar view (android.R.id.tabs) and then cast it to a Tabhost or a ViewGroup then you can get each of the tabs via .getChildAt(x) where x is the index of the tabs.
ViewGroup tabs = (ViewGroup) solo.getView(android.R.id.tabs);
View viewYouWantToDoStuffWith = tabs.getChildAt(x); //change x to the index you want.
In your case you would then want something like:
solo.clickOnView(viewYouWantToDoStuffWith);
you can use method solo.clickOnView(solo.getView(resourceId));
where resourceId could be something like R.id.id_Of_Button.
see this link in that they are using image + text. so remove the text made as image that you have to do it.
http://www.androidhive.info/2011/08/android-tab-layout-tutorial/
this is only for text you can set that with image and made as custom tab.
http://www.androidpeople.com/android-tabhost-tutorial-part-1
Hope it will work for you .

Can i take tab bar and custom title-bar in same Activity

I have Tab-bar and custom title-bar in same activity.In static mode am able to display tab-bar and custom title-bar in the same activity. But when i assign dynamic values to custom title-bar attributes it shows error as
AndroidRuntimeException: You cannot combine custom titles with other title features
Please provide any suggestions.
Thanks in advance
Try:
this.getActionBar().setDisplayShowCustomEnabled(true);
this.getActionBar().setDisplayShowTitleEnabled(false);
this.getActionBar().setDisplayUseLogoEnabled(true);
final LayoutInflater inflator = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View v = inflator.inflate(R.layout.header_bar, null);
//if you need to customize anything else about the text, do it here.
//I'm using a custom TextView with a custom font in my layout xml so all I need to do is set title
((TextView)v.findViewById(R.id.header_bar_title)).setText(this.getTitle());
//assign the view to the actionbar
this.getActionBar().setCustomView(v);
and make sure you do this before setContentView() method.

Categories

Resources