I'm having a really hard time changing the color of my TabWidget. I've looked at several posts and tried them out, but none of them worked for me. I'm trying to change the default (blue) color scene to green.
Image of my app
My xml code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity"
android:id="#+id/relativeLayout">
<TabHost
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/tabHost"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:tabStripEnabled="false">
</TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="#+id/tab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:id="#+id/listFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:id="#+id/tab3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
The way to change the color of the tabs programmatically is by using
for(int i=0;i<mTabHost.getTabWidget().getChildCount();i++)
{
mTabHost.getTabWidget().getChildAt(i)
.setBackgroundColor(Color.parseColor("#00304E"));
}
To change the color of the currently selected tab,
mTabHost.getTabWidget().getChildAt(mTabHost.getCurrentTab())
.setBackgroundColor(Color.parseColor("#008EE8"));
Related
Okey guys i have LineChart made with achartengine, here is screenshot:
https://www.dropbox.com/s/yk5nipe3b6upcaa/11414548_10205801109521047_408896835_n.jpg?dl=0
1st XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:id="#+id/linearLayout1"
android:orientation="horizontal">
</LinearLayout>
<TextView
android:layout_below="#+id/linearLayout1"
android:id="#+id/description"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Description:"
android:textStyle="bold"
/>
<TextView
android:layout_below="#+id/description"
android:id="#+id/descriptionText"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
2ndXML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="#+id/linearLayout1" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1"/>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/description"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Description:"
android:textStyle="bold"
/>
<TextView
android:id="#+id/descriptionText"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
Here is code for onCreate() method:
description=(TextView)findViewById(R.id.descriptionText);
description.setText("sadasdasdas");
setRendererStyling();
if (mChartView == null) {
LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout1);
mChartView = ChartFactory.getLineChartView(this, mDataset,
mRenderer);
mRenderer.setSelectableBuffer(100);
layout.addView(mChartView, new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
} else
mChartView.repaint();
My problem is that I want to put two TextViews after chart.I tried with this two different xml and no result.
I am only getting Description: on my activity...
EDIT FOR Dharm
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:id="#+id/linearLayout1"
android:orientation="horizontal"
android:layout_above="#+id/scrollView">
</LinearLayout>
<ScrollView
android:id="#+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Description:"
android:textStyle="bold"
/>
<TextView
android:layout_below="#+id/description"
android:id="#+id/descriptionText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
Use a RelativeLayout and arrange the graph to have its bottom align with the top of your TextViews. Your first xml is close, but it is creating a LinearLayout that fills the screen and then placing the TextView below that.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:id="#+id/linearLayout1"
android:orientation="horizontal"
android:layout_above="#+id/description">
</LinearLayout>
<TextView
android:id="#+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Description:"
android:textStyle="bold"
android:layout_alignParentBottom="true" />
<TextView
android:layout_toRightOf="#+id/description"
android:id="#+id/descriptionText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
Having an issue with Android Studio. Basically, I'm doing as it says however it's producing an error which I can't figure out.
I have tried using android:id="android:id/tabs". Alas this did not work either
Here is the XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".FindMyCar"
android:id="#+id/">
<TabHost
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tabHost"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TabWidget
android:id="android:id_tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/tabFind"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="#+id/tabRandom"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"></LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</RelativeLayout>
I have tried using android:id="android:id/tabs"
It should be android:id="#android:id/tabs"
I am trying to add action bar on top, and two containers below the action bar, each of the containers I want to have 80% of width and 20% of width.
Here is my XML file which is not working:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.hany_action_bar.MainActivity"
tools:ignore="MergeRootFrame" >
<LinearLayout
android:id="#+id/menu_container"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:weightSum="20"
android:orientation="horizontal" >
</LinearLayout>
<LinearLayout
android:id="#+id/main_container"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:weightSum="80"
android:orientation="horizontal" >
</LinearLayout>
</FrameLayout>
Can try like this :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2"
tools:context="com.example.hany_action_bar.MainActivity"
tools:ignore="MergeRootFrame" >
<LinearLayout
android:id="#+id/menu_container"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1.6"
android:background="#000"
android:orientation="horizontal" >
</LinearLayout>
<LinearLayout
android:id="#+id/main_container"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="0.4"
android:background="#fff"
android:orientation="horizontal" >
</LinearLayout>
</LinearLayout>
I have just implemented Tabs with swipe using FragmentTabHost in android. But there's an issue in the layout. When i running my application i get the below output. The swipe is only work for the below part
I Want something like
The code of XML i'm using is
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.app.FragmentTabHost
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0" />
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
Have a TabHost that doesn't center the views even though I set the views layout_gravity to center_horizontal. Here is my XML, the button is all I've added to the tab1 layout so far.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabHost android:id="#+id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:layout_width="fill_parent" android:id="#+id/linearLayout1" android:layout_height="fill_parent" android:orientation="vertical">
<TabWidget android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="#android:id/tabs"></TabWidget>
<FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="#android:id/tabcontent">
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="#+id/tab1">
<Button android:layout_width="wrap_content" android:id="#+id/button1" android:layout_gravity="center_horizontal" android:text="Button" android:layout_height="wrap_content"></Button>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="#+id/tab2"></LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="#+id/tab3"></LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
you have to set gravity at the parent!
Try setting the android:gravity attribute on the parent of the button instead.
Like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost android:id="#+id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:layout_width="fill_parent" android:id="#+id/linearLayout1" android:layout_height="fill_parent" android:orientation="vertical">
<TabWidget android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="#android:id/tabs"></TabWidget>
<FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="#android:id/tabcontent">
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="#+id/tab1" android:gravity="center_horizontal">
<Button android:layout_width="wrap_content" android:id="#+id/button1" android:text="Button" android:layout_height="wrap_content"></Button>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="#+id/tab2"></LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="#+id/tab3"></LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost></LinearLayout>