Something is wrong with xml Tabs - android

This is my Tabs in APP
First Tab
Second Tab
What am I doing wrong?
My activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
app:srcCompat="#drawable/header_logo" />
<TabHost
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_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"></TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
My first activity xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.mapbox.mapboxsdk.maps.MapView
android:id="#+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:mapbox_cameraTargetLat="59.908008"
mapbox:mapbox_cameraTargetLng="30.319100"
mapbox:mapbox_cameraZoom="8"/>
</FrameLayout>
And second activity
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
app:srcCompat="#drawable/mapbox_compass_icon" />
<TextView
android:id="#+id/idtest"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Информация"></TextView>
</LinearLayout>
I need the design to look like this
How i see it in Android Studio
I don’t understand where the problem is, I created everything from the lesson in the Russian forum (I am Russian-speaking)

Your xml file is ready
next Put this code in MainActivity.java file for adding Tab in TabHost
//Assign id to Tabhost.
TabHostWindow = (TabHost) findViewById(android.R.id.tabhost);
//Creating tab menu.
TabSpec TabMenu1 = TabHostWindow.newTabSpec("First tab");
TabSpec TabMenu2 = TabHostWindow.newTabSpec("Second Tab");
//Setting up tab 1 name.
TabMenu1.setIndicator("Tab1");
//Set tab 1 activity to tab 1 menu.
TabMenu1.setContent(new Intent(this, TabActivity_1.class));
//Setting up tab 2 name.
TabMenu2.setIndicator("Tab2");
//Set tab 3 activity to tab 1 menu.
TabMenu2.setContent(new Intent(this, TabActivity_2.class));
TabHostWindow.addTab(TabMenu1);
TabHostWindow.addTab(TabMenu2);
for more info visit this

You just need to add a separate layout file which includes the tabs and your actionBar

Related

Navigation inside TabHost

I have a problem with the navigation: I created a tabbed application using MvxTabsFragmentActivity and all worked great until I start navigating inside the tabs; If I navigate one level inside one tab and then I change the tab, on the second tab I am presented with the content from the first tab. Have anyone encountered this problem?
I created the tabs using TabHost.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/actualtabcontent"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_above="#+id/tabContainer"/>
<LinearLayout android:id="#+id/tabContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<TabHost android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white">
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="7dp"
android:background="#drawable/gradient_border_top"
android:orientation="horizontal" />
<TabWidget android:id="#android:id/tabs"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_weight="0"
android:background="#color/white" />
<FrameLayout android:id="#android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
</LinearLayout>
</TabHost>
</LinearLayout>
</RelativeLayout>
Each time I am navigating inside the tabs the content of actualtabcontent is replaced.
Expected navigation:
Tab A: A1 -> A2.
Tab B: B1 -> B2.
Switching between tabs should display the content for the selected tab
'You need to clear the cache while moving to the next tab.
if you are getting data from server using volley then use'
stringRequest.setShouldCache(false);
'before passing your stringrequest to requestqueu.'
'if you are using something else then find a way to clear cache before loading new data.'
'hope you get the answer if not please explain your question.'

Android ViewPager Indicator layout

Hi Have a a VewPager indicator that will show what Fragment I am currently Viewing. I need to add a button under the circles but when I do i don't see any button at all.
My xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.kassisdion.library.ViewPagerWithIndicator
app:arrow.enable="true"
app:arrow.width="10dip"
app:arrow.height="500dip"
app:round.enable="true"
app:round.size="15dip"
app:round.drawable="#drawable/background_rounded"
app:round.color.default="#android:color/white"
app:round.color.selected="#android:color/holo_blue_light"
android:id="#+id/viewPagerWithIndicator"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.kassisdion.library.ViewPagerWithIndicator>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Skip"/>
</LinearLayout>
I tried changing the Layout but that just threw exceptions.
How can I do this?
Thanks

TabHost - aligned bottom, disabled and showing no view

I know this is a bit odd but bear with me.
I have a custom view, that extends TabHost and inflates a XML.
It includes several views, it is aligned to bottom and everything works great.
The problem is when I put the TabHost in a different activity, where I don't want to see any of the TabHost views. Only the TabHost tabs on top of the activity layout. Basically, I want the TabHost to be there as a disabled bottom bar.
here's the TabHost XML (which works great and aligned to bottom, as long as I toggle between one of the custom views):
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
>
<CustomView#1
android:id="#+id/tab_watch_me"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<CustomView#2
android:id="#+id/tab_messages"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<CustomView#3
android:id="#+id/tab_search_results"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<CustomView#4
android:id="#+id/tab_my_profile"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<CustomView#5
android:id="#+id/tab_user_profile"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0" />
</LinearLayout>
</TabHost>
Here's the activity XML (the one that I don't want the tabhost views to be shown, only to align the tabhost buttons to the bottom):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<customview.HeaderView
android:id="#+id/header_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
**//Notice that I don't want to show any of the customViews the tabhost hold. only the tabhost tabs/buttons**
<customview.MyTabHost
android:id="#+id/settings_tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Let me know if you need more code in order to help!
Thank you!
My RelativeLayout solution in case this helps anyone. I'm still looking for a better solution if anyone has to offer.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<customview.HeaderView
android:id="#+id/header_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<Any other view
android:layout_below="#+id/header_view"
/>
<customview.MyTabHost
android:id="#+id/settings_tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true" />
</RelativeLayout>

How do I add TabWidget and FrameLayout to TabHost, manually?

I've created a class which I want to use to create tabs(I dont want to use an Activity). Now, my tabs.xml file contains:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tab_host"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="5dp" >
<TabWidget
android:id="#+id/tabs" //Not #android:id="#android:id/tabs
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#+id/tabcontent" //Not#android:id="#android:id/tabcontent
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<include
android:id="#+id/tab_horizontal_scroll" layout="#layout/gallerymodule"/>
</FrameLayout>
</LinearLayout>
</TabHost>
I understand that the TabHost object do not retrieve references to TabWidget and FrameLayout.
I would like to know how to add these references manually? Thanks.

How to add tabs at bottom

I have a tabhost which contains three tabs, connected with three activities. All three tabs are in the upper side. How can I make these three tabs at the bottom?
I found this, but there are still some problems.
This is my tabhost XML file:
<?xml version="1.0" encoding="UTF-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"/>
</LinearLayout>
</TabHost>
In my TabActivity class, I have following code:
setContentView(R.layout.tabs);
TabHost mTabHost = (TabHost)findViewById(android.R.id.tabhost);
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(new Intent(AndroisTabViewActivity.this,TabActivity1.class)));
mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").setContent(new Intent(AndroisTabViewActivity.this,TabActivity1.class)));
mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("TAB 3").setContent(new Intent(AndroisTabViewActivity.this,TabActivity1.class)));
mTabHost.setCurrentTab(0);
There is one activity named TabActivity1 which I have also included in Manifest file. But it is showing the error:
Can't get the activity TabActivity1.
I assume you want to show "Tab" at bottom of the window, just try this:
<RelativeLayout
android:layout_width="match_parent"
android:id="#+id/linearLayout1"
android:layout_height="match_parent">
<TabWidget
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#android:id/tabs"
android:layout_alignParentBottom="true">
</TabWidget>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#android:id/tabcontent">
</FrameLayout>
</RelativeLayout>
If you want to use the LinearLayout:
<?xml version="1.0" encoding="UTF-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</TabHost>
With this solution, the tab content will take no space firstly, the TabWidget will take its own space, then the remaining space will be given to the tab content.

Categories

Resources