I got this image in a tab but it's too small. how can I scale it up or make it fill the tab
final TabHost tabHost = getTabHost(); //edit: added this line
tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("Discussion",
getResources().getDrawable(R.drawable.forum))
.setContent(new Intent(this, MyActivity.class)));
Set a LinearLayout as a child of the TabHost and add your image to that LinearLayout
You won't be able to with the method you're using. The drawable is mean't to be a small icon. If you want something custom, you'll have to use setIndicator(View) instead. I'd image you'd create an ImageView set to use the drawable you want and pass that in. If you wanted the text "Discussion" to still be there, you'd had to create a layout with an ImageView and TextView and use that.
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.
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 .
In my application i use the tabhost in linear layout, tabhost contains 4 tabs. The size of the tabwidget is very very high and it shows title very small. Can any one help me how to reduce the size of tabwidget.
I would insist to create custom Tabs using setIndicator(View). So, create a TextView of your desired size and set it to the TabWidget. Here is an Tutorial for the same with Example.
You can just inflate a TextView and set it to the TabWidget using
View view = LayoutInflater.from(context).inflate(R.layout.your_custom_tab-layout,
null);
TextView tv = (TextView) view.findViewById(R.id.my_text_view);
TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tv).
setContent(intent);
mTabHost.addTab(setContent);
I'm not clear on exactly what you're looking to do here, but I'll make a guess at it.
If you don't want space to be taken up by graphics (in other words, have text only) you can set the height and graviy of the widget to effectively remove the space that is used by the graphic, making for a much more compact tab label (vertically).
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:gravity="bottom" />
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/
Anyone know how facebook did this:
From what I know we cannot change the height of tabhost. I'm guessing that they laid the "Frank Cho" view over the tabhost to give it the appearance of being shorter but I may be wrong. Anyone know what's going on?
You actually can have custom looking tab widgets. You need to set the tab indicator to some custom layout (with your drawables) and you should be good to go.
Here's an semi-example:
final TabHost host = getTabHost();
final TextView indicator = (TextView) getLayoutInflater().inflate(
R.layout.tab_indicator,
getTabWidget(), false);
indicator.setText("Tab title");
host.addTab(host.newTabSpec("The tab tag")
.setIndicator(indicator)
.setContent([put your content here]));
}
Where the tab_indicator layout can look like this:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tab_label"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:textSize="14sp"
android:textStyle="bold"
android:minHeight="38dp"
android:background="#drawable/minitab" />
The minitab drawable is a drawable item selector (so you need to have an image for selected, default, pressed, and unselected). The facebook app used some white drawable image for the default tab and the blue gradient drawable for the unselected tabs.
Check out the Google IO Schedule app for a full working example: http://code.google.com/p/iosched/ (and specifically the TrackDetailActivity.java)
Somebody else had what I think is the correct answer, but deleted it for some reason...
The height in question is not that of the TabHost, but of the TabWidget.
Try using the version of setIndicator() that takes a View instead of just a String or String plus drawable resource. While I have not played with this yet, my understanding is that it solves this problem nicely.
Be careful, though, that you don't wind up with tabs that are too tough to tap.