Android: horizontal scroll in tabhost - android

I created a tabhost in my activity in this way:
mTabHost = getTabHost();
mTabHost.addTab(mTabHost.newTabSpec("Phone").setIndicator("TELEFONO", iconContact).setContent(R.id.linear1));
mTabHost.addTab(mTabHost.newTabSpec("Maps").setIndicator("MAPPE", iconMap).setContent(R.id.scroll2));
mTabHost.addTab(mTabHost.newTabSpec("Cam").setIndicator("WEBCAM", iconWebcam).setContent(R.id.scrollWebcam)); //metto il tab per le webcam
mTabHost.addTab(mTabHost.newTabSpec("Setting").setIndicator("IMPOSTAZ.", iconImpostaz).setContent(R.id.scrollImp));
mTabHost.setCurrentTab(0);
but now the number of tabs required is incrising, so I need to scroll the tabs horizontally. How can I do this?

This library is exactly what you are looking for :
https://github.com/JakeWharton/Android-ViewPagerIndicator

Related

Change TabWidget Indicator colour

I'm hoping someone can help. I am looking to change the indicator colour of my tab widget.
I had used the action bar tabs and had them styled correctly, however, I am using a nav drawer and require it to open over the tabs so I have changed to a tabhost/tabwidget.
I have followed this link:
Customizing tab indicator images in android?
Here is the strange part, I can change the tab colour, the divider colour, but when I try to change the tabStripLeft and the tabStrip right it won't work. I also tried to remove the strip below the indicator but that wouldn't work
android:background="#color/tab"
android:divider="#color/appPink"
android:tabStripLeft="#color/appPink"
android:tabStripRight="#color/appPink"
android:tabStripEnabled = "false"
I have tried drawables for the indicator too in case you may think this may be the problem. Does anyone have any ideas on this?
Here is how I've set them up in my activity:
private FragmentTabHost mTabHost;
mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.container);
mTabHost.addTab(mTabHost.newTabSpec("home").setIndicator("Home"), PlaceholderFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("favourites").setIndicator("Settings"), settings_fragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("settings").setIndicator("Favourites"), mark_list_fragment.class, null);
If anyone has any thoughts I'd appreciate hearing them.

Customize tabs android

This is how I want the tabs to look:
http://img14.imageshack.us/img14/5696/tabort.png
This is how they look using tabHost:
http://img684.imageshack.us/img684/1030/tabort2.png
So I want to remove the border around the images. Instead, I want to have the greyish background image behind the tabs. Can anyone please help me with this (I'm new to Android)?
Here is some relevant code:
// Create an Intent to launch an Activity for the tab
intent = new Intent().setClass(this, WashActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("washer").setIndicator("",
res.getDrawable(R.drawable.wash_tab))
.setContent(intent);
tabHost.addTab(spec);
You can use Buttons positioned side-by-side in Relative Layout with custom background images instead of TabView.
set custom view ( imageview or image with text in ur case ) using setView() instead setIndicator() will work for you .
TabHost is deprecated now . so better to use fragment with compatibility package .

Android Change Image

I am trying to develop my first game but i am having trouble, it is something really simple which i am confused about. Basically I need to load 2 images i created in photoshop but if they are clicked, a different image of the same shape will be drawn on top, making it look like its been selected, then if someone clicks on the other image, image one goes back to the initial state and another image for the second one is drawn on top... How can I achieve this?
I am just having trouble on how to load the initial images to the screen and thenbe able to swap them with the others...
Thank you
If I understand your question right, it sounds like using tabs would be a solution.
Smth like this might be a first step to your game
public class MyTab extends TabActivity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The acWednesdaytivity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, YourWithImage1.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("tab1").setIndicator("tab1",
res.getDrawable(R.drawable.ic_tab))
.setContent(intent);
tabHost.addTab(spec);
}}
and your ic_tab will look like
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected, use grey img-->
<item android:drawable="#drawable/ic_tab_grey"
android:state_selected="true" />
<!-- When not selected, use white img-->
<item android:drawable="#drawable/ic_tab_white" />
</selector>
I am new myself to andorid. Hope this will help somehow.
I'm new to Android too, so not sure if I have the correct answer. But here is what I might try:
Have your activity implement onclicklistener
In the onCreate method, find your ImageView using findViewById
call the ImageView's setOnclickListener method
Handle the onclick event
In the event handler, call the setImageResource of the ImageView to switch the image.
Again, I'm new to Android too so I'm not talking from experience. I hope this helps.
See the following link which I happened to come across:
http://www.higherpass.com/Android/Tutorials/Working-With-Images-In-Android/

Custom tabs in Android

I am trying to change the content of the tab header but am struggling. I can see that it is possible to pass a View to the setIndicator() method. I tried this and got a removeParent() warning which I dont understand. Has anyone managed to do this successfully. If so can you explain how you did it please?
Clive
This problem occurs when you use the same view in different tabs. You must use a different view. This is what I did:
view.setImageResource(R.drawable.videotab);
view1.setImageResource(R.drawable.musictab);
intent = new Intent().setClass(this, CustomList.class);
spec = tabHost.newTabSpec("Video").setIndicator(view)
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, CustomListOne.class);
spec = tabHost.newTabSpec("Music").setIndicator(view1)
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
You don't have to use different Views. You can simply inflate the same layout again when you need it. That means you inflate your layout, set everything you need on your different Views and then you set it as your indicator. If you need another tab just do it again.

How can change my TabHost?

I have a tabhost,
e.g:
final TabHost tabs = getTabHost();
tabs.setup();
TabHost.TabSpec spec = null;
spec = tabs.newTabSpec("search");
spec.setContent(new Intent(this, Search.class));
spec.setIndicator("search");
tabs.addTab(spec);
in this tabhost is a Intent,and in the activity must change to other activity,
question is I hope the other actitivy at same tabhost switch?
Can do this?
I had this problem almost a 3 months ago. you can not replace the activity. Because activities are open in new screens. so you have to use the views and layout to achieve what you are want to do. use the setVisiblity and isShown methods you can hide and release yours view. Hope it make some sense on it.

Categories

Resources