I have a 11 Fragment in the viewPager, and when tablayout want to show these 11 fragment name , their text not show correctly.
this is the screenshot of my problem :
and this is my activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/xmlDrawerLayoutRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activities.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v7.widget.Toolbar
android:id="#+id/xmlToolbarMain"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<!-- navigation opener -->
<ImageButton
android:id="#+id/btnHomeToolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="?attr/colorPrimary"
android:paddingRight="10dp"
android:clickable="true"
android:src="#drawable/menu"/>
<!-- app name -->
<TextView
android:id="#+id/txttitleToolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title"
android:layout_gravity="right"
android:textColor="#ffffff"
android:textSize="16sp"
android:paddingRight="10dp"/>
<!-- search box-->
<ImageButton
android:id="#+id/btnSearchToolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:paddingLeft="10dp"
android:clickable="true"
android:src="#drawable/search"
android:background="?attr/colorPrimary"/>
</android.support.v7.widget.Toolbar>
<!-- Tablayout -->
<android.support.design.widget.TabLayout
android:id="#+id/xmlTabLayoutMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/xmlToolbarMain"
android:background="?attr/colorPrimary"
android:elevation="8dp"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<!-- ViewPager -->
<android.support.v4.view.ViewPager
android:id="#+id/xmlViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/xmlTabLayoutMain"/>
<!-- navigationDrawer -->
<!--<android.support.design.widget.NavigationView-->
<!--android:id="#+id/xmlNavigation"-->
<!--android:layout_width="198dp"-->
<!--android:layout_height="match_parent"-->
<!--android:layout_gravity="start"-->
<!--app:headerLayout="#layout/header_navigation_view"-->
<!--app:menu="#menu/nav_menu" />-->
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
and I set this on my tablayout in the MainActivity.java but still i have a problem :
appTabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
try to use like that
<android.support.design.widget.TabLayout
android:id="#+id/xmlTabLayoutMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/xmlToolbarMain"
android:background="?attr/colorPrimary"
android:elevation="8dp"
app:tabMode="scrollable"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
also try to use if not working
app:tabGravity="fill"
tabMode will make your tab scrollable.So it should solve your problem.
You could create a custom style for your text and there define all the constraints like normal text view attributes. then just set tab text appearance to your custom style.
Your tab layout will be like -
<android.support.design.widget.TabLayout
android:id="#+id/tabs_home"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:tabTextAppearance="#style/MineCustomTabText"
app:tabMode="scrollable"
/>
And in your style.xml file define the style, like this -
<style name="MineCustomTabText" parent="TextAppearance.Design.Tab">
<item name="android:textSize">16sp</item>
<item name="android:maxLines">1</item>
</style>
Related
I'm trying to achieve AppbarLayout with background, inside the AppbarLayout to have a static Toolbar, under the the Toolbar i'm using a CollpasingToolBar that now contains a Toolbar and later supposed to include also a Custom View that it's content will be scaled according to scrolling position, and in the bottom of the AppBarLayout i'm using a TabLayout.
The issue i can't resolve is: i want that the AppbarLayout Drawable will be also be spread over the status bar, currently i failed to achieve this.
I'm attaching the xml layout and also a screen shot:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:windowDrawsSystemBarBackgrounds = "true"
android:statusBarColor="#android:color/transparent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="220dp"
android:background="#drawable/winterscenery"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsingToolbarLayout"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="180dp"
app:statusBarScrim="#android:color/transparent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
android:fitsSystemWindows="true"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="One" />
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Two" />
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Three" />
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/content_text_one" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/content_button" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/content_text_two" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
After editing Manifest file :
<activity android:name=".ExitUntilCollapsedActivity" android:theme="#style/JustTryStyle" />
And creating the JustTryStyle style:
<style name="JustTryStyle" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:navigationBarColor">#android:color/transparent</item>
</style>
I got the following apperance:
In your theme you need to add
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:navigationBarColor">#android:color/transparent</item>
Edit:
Add these two to the theme your activity uses as defined in the AndroidManifest.
If other activities also use use this theme but should not have the transparent navigationbar then you need to extend it and update your AndroidManifest accordingly.
Edit 2: try adding <item name="android:windowTranslucentStatus">true</item> instead or additionally
Edit 3: also add fitSystemWindow=true to constraintlayout and appbar
Below is a picture of my app UI (actionBar/toolBar + webView + tabs). As you can see, the AB/toolbar + tabs are transparent (black color hence no background) but it refuses to fold above my webView (EdgeScrollViewPager) in the background. I am setting the color to #null in both the toolbar and tabBar. I do not know what I do for logical errors in the code, ie why the actionBar/toolbar and tabBar do not lie on top of the dark blue background (webView).
app_bar_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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.MainActivity">
<include layout="#layout/toolbar" />
<com.ui.util.EdgeScrollViewPager
android:id="#+id/content_main_viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:visibility="visible"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</com.ui.util.EdgeScrollViewPager>
<android.support.design.widget.TabLayout
android:id="#+id/content_main_tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:tabMaxWidth="0dp"
app:tabGravity="fill"
app:tabMode="fixed"
app:tabTextAppearance="#style/ML.Tab"
app:tabPadding="0dp"
app:tabIndicatorHeight="0dp"
app:tabIndicatorColor="#null"
android:visibility="visible"
android:background="#null"
app:background="#null">
</android.support.design.widget.TabLayout>
</LinearLayout>
toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
app:theme="#style/ML.Toolbar"
app:popupTheme="#style/ML.Toolbar.PopupTheme"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
>
<include layout="#layout/topbar_loading_indicator" />
</android.support.v7.widget.Toolbar>
style.xml
<style name="ML.Toolbar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#null</item>
<item name="background">#null</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
</style>
Try this:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.MainActivity">
<include layout="#layout/app_toolbar" />
<com.ui.util.EdgeScrollViewPager
android:id="#+id/content_main_viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:visibility="visible"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</com.ui.util.EdgeScrollViewPager>
<android.support.design.widget.TabLayout
android:id="#+id/content_main_tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentBottom="true"
android:background="#null"
android:visibility="visible"
app:background="#null"
app:tabGravity="fill"
app:tabIndicatorColor="#null"
app:tabIndicatorHeight="0dp"
app:tabMaxWidth="0dp"
app:tabMode="fixed"
app:tabPadding="0dp"
app:tabTextAppearance="#style/ML.Tab">
</android.support.design.widget.TabLayout>
If you want to Float the views You can either use relative layout or frame layout.
I am working on the transparent status bar and bottom navigation bar visible. I have achieved the same with my last question: Gradient status bar with BottomNavigationView
But now, I have a fragments in which fitsSystemWindows is not
working. I have layout like Activity -> Viewpager -> Fragments ->
Viewpager -> child Fragments.
I have gone through many attempts from stack overflow but still no luck :
Appbar fitsSystemWindows - Inside a ViewPager
Android - ViewPager fitsSystemWindows (fullscreen) not working
Setting a child view to fit system windows
Android fitsSystemWindows not working when replacing fragments
How to apply gradient to status bar in android?
I have added this styles :
<item name="android:windowContentOverlay">#null</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:navigationBarColor">#000</item>
<item name="colorControlNormal">#FFFFFF</item>
<item name="colorPrimaryDark">#android:color/transparent</item>
In v21/style :
<item name="colorPrimaryDark">#android:color/transparent</item>
In layout, I have added fitsSystemWindows to each fragment as well as activity.
Activity layout:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<com.mobile.lendlease.views.WrapContentViewPagerBottomTab
android:id="#+id/viewPagerContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/viewDivider"
android:fitsSystemWindows="true" />
<View
android:id="#+id/viewDivider"
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_above="#+id/bottomNavigation"
android:background="#color/default_border" />
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottomNavigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:paddingBottom="#dimen/margin_12"
android:paddingEnd="#dimen/margin_12"
android:paddingStart="#dimen/margin_10"
android:paddingTop="#dimen/margin_10"
app:itemBackground="#color/white"
app:menu="#menu/navigation" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
</layout>
One of fragment layout:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbarLayout"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorScreenBackground"
android:focusable="true"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="#dimen/toolbar_height"
android:layout_marginBottom="#dimen/margin_20"
android:background="#drawable/toolbar"
android:gravity="bottom"
android:fitsSystemWindows="true"
app:layout_scrollFlags="enterAlways"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="#dimen/margin_18">
<ImageView
android:id="#+id/ivHome"
android:layout_width="159dp"
android:layout_height="29dp"
android:scaleType="centerInside"
android:src="#drawable/logo" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:orientation="horizontal">
<ImageView
android:id="#+id/ivSearch"
android:layout_width="#dimen/margin_47"
android:layout_height="32dp"
android:contentDescription="#string/app_name"
android:scaleType="fitXY"
android:src="#drawable/ic_search" />
<TextView
android:id="#+id/ivMall"
style="#style/notoSansSemiBoldStyle"
android:layout_width="58dp"
android:layout_height="32dp"
android:layout_marginEnd="#dimen/margin_18"
android:layout_marginStart="#dimen/margin_10"
android:background="#drawable/search_bg_shape"
android:gravity="center"
android:text="#string/mall_all"
android:textAllCaps="false"
android:textColor="#color/gradient_card_color1"
android:textSize="#dimen/font_12"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:minHeight="?attr/actionBarSize"
app:tabBackground="#drawable/tab_indicator_line_selected"
app:tabGravity="center"
app:tabIndicatorColor="#android:color/transparent"
app:tabMode="scrollable"
app:tabSelectedTextColor="#color/colorBlackLight"
app:tabTextAppearance="#style/themeTabText"
app:tabTextColor="#color/colorBlackLight" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewPagerContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
</layout>
Here is what I did: I created a style for the text
<!-- Change tab text appearance -->
<style name="MyCustomTextAppearance" parent="TextAppearance.Design.Tab">
<item name="textAllCaps">false</item>
<item name="android:textAppearance">#style/CustomTabWidgetText</item>
</style>
<style name="CustomTabWidgetText"
parent="#android:style/TextAppearance.Widget.TabWidget">
<item name="android:textSize">16sp</item>
</style>
then I set it to my tablayout
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.HomeActivity"
tools:showIn="#layout/app_bar_main">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:titleTextColor="#ffffff"
/>
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/toolbar"
android:background="?attr/colorPrimary"
app:tabSelectedTextColor="#ffffff"
app:tabTextAppearance="#style/MyCustomTextAppearance"
app:tabTextColor="#ffffff" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="#id/tab_layout" />
</RelativeLayout>
Here is the result:
As you can see, the "D-day complete" text is smaller than others. I have request to make its size equal to others but I dont know how. Please help me, thanks.
You can try to set padding in TabLayout
(app:tabPaddingStart="-1dp", app:tabPaddingEnd="-1dp")
like
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/toolbar"
android:background="?attr/colorPrimary"
app:tabSelectedTextColor="#ffffff"
app:tabTextAppearance="#style/MyCustomTextAppearance"
app:tabTextColor="#ffffff"
app:tabPaddingStart="-1dp"
app:tabPaddingEnd="-1dp"/>
It helped me)
Per this post, this worked really well for me:
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
app:tabGravity="fill"
app:tabIndicatorHeight="5dp"
/>
The tabMode and tabGravity attributes did the trick. This lets the labels span as long as need be and scroll like so:
After experiencing something similar, and after reading the TabLayout source code, I try overriding a dimension, in my dimens.xml file, like this:
<dimen name="design_tab_text_size_2line" tools:override="true">48sp</dimen>
and don't forget to add the namespace in the root of your file, like this:
<resources xmlns:tools="http://schemas.android.com/tools">
and it works for me.
Hope it helps!
EDIT :
It seems like it doesn't work on every situation (it's actually supposed to work when your text has two lines or more), but it helps when the style doesn't work. So what I do is that I use both technics (style and overridden dimension).
This is works for me:
app:tabMode="scrollable"
app:tabGravity="fill"
In think the best approach is to use a custom view. You will have the maximum flexibility. For instance:
<com.google.android.material.tabs.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="36dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tabGravity="fill"
app:tabMode="fixed">
<com.google.android.material.tabs.TabItem
android:id="#+id/tab1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout="#layout/view_tab_text_layout" />
<com.google.android.material.tabs.TabItem
android:id="#+id/tab2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout="#layout/view_tab_text_layout" />
<com.google.android.material.tabs.TabItem
android:id="#+id/tab3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout="#layout/view_tab_text_layout" />
<com.google.android.material.tabs.TabItem
android:id="#+id/tab4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout="#layout/view_tab_text_layout" />
</com.google.android.material.tabs.TabLayout>
The view_tab_text_layout could be:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:background="#color/colorPrimary"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatTextView
android:maxLines="1"
android:lines="1"
android:id="#+id/tabTextView"
android:textColor="#android:color/white"
android:textAllCaps="false"
android:textSize="18dp"
android:textStyle="bold"
app:autoSizeMaxTextSize="18dp"
app:autoSizeMinTextSize="12dp"
android:ellipsize="end"
app:autoSizeTextType="uniform"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
tools:text="Tab 1" />
</FrameLayout>
And you can access the the custom views like this:
tabLayout = findViewById(R.id.tabs);
((TextView) tabLayout.getTabAt(0).getCustomView().findViewById(R.id.tabTextView)).setText(R.string.tab1);
((TextView) tabLayout.getTabAt(1).getCustomView().findViewById(R.id.tabTextView)).setText(R.string.tab2);
((TextView) tabLayout.getTabAt(2).getCustomView().findViewById(R.id.tabTextView)).setText(R.string.tab3);
((TextView) tabLayout.getTabAt(3).getCustomView().findViewById(R.id.tabTextView)).setText(R.string.tab4);
As full working example could be found here: https://bitbucket.org/mspapant/tablayout-example
I am tying to get transparent toolbar over RecyclerView contains custom Relative Layout i called it customHeader . my layout in the main activity is like:
i use android support design library v.22.2.1 and other support libraries with the same version
things are fine except that, i am getting toolbar with my primary color rather than transparent toolbar even though, i have removed background color from toolbar layout.
this is the result i have got:
What i want is transparent toolbar but should get filled with primary color only when i scroll up
my activity_main layout is:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
android:id="#+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsingToolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="#+id/content_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/btnCreate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_marginBottom="#dimen/btn_fab_margins"
android:layout_marginRight="#dimen/btn_fab_margins"
android:src="#drawable/share"
app:borderWidth="0dp"
app:elevation="6dp"
app:pressedTranslationZ="12dp" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="#+id/vNavigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/WHITE"
app:itemIconTint="#color/primary_text"
app:itemTextColor="#color/primary_text"
app:headerLayout="#layout/drawer_header"
app:menu="#menu/drawer_menu"/>
</android.support.v4.widget.DrawerLayout>
then the layout in my fragment is:
<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">
<!-- Story list in main page -->
<com.creativeLabs.news.util.MySwipeRefreshLayout
android:id="#+id/swipe_refresh_story"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity$PlaceholderFragment">
<android.support.v7.widget.RecyclerView
android:id="#+id/list_view_story_list"
android:overScrollMode="never"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</com.creativeLabs.news.util.MySwipeRefreshLayout>
</RelativeLayout>
my customHeader layout is:
<?xml version="1.0" encoding="utf-8"?>
<com.creativeLabs.news.ui.view.SlideTopStory
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_marginBottom="#dimen/story_list_item_margin_vertical"
android:layout_width="match_parent"
android:layout_height="#dimen/slide_image_height">
<ImageView
android:id="#+id/ivStoryimage"
android:contentDescription="#string/story_title"
android:scaleType="centerCrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<ProgressBar
android:id="#+id/loading_bar"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!-- A mask view -->
<View
android:background="#drawable/title_slide_background"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="70dip"/>
<View
android:background="#drawable/title_slide_background1"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="70dip"/>
<TextView
android:id="#+id/title"
android:layout_alignParentBottom="true"
android:textColor="#android:color/white"
android:textSize="#dimen/text_size_large"
android:gravity="center_vertical"
android:paddingLeft="#dimen/slide_image_title_padding"
android:paddingRight="#dimen/slide_image_title_padding"
android:paddingEnd="#dimen/slide_image_title_padding"
android:layout_marginBottom="#dimen/slide_image_title_margin"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.creativeLabs.news.ui.view.SlideTopStory>
My app thems.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorControlNormal">#android:color/white</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
.......
.......
in the manifest -> application tag:
android:theme="#style/AppTheme.WithoutActionBar">
in my activities and fragments, i coded nothing regarding toolbar colors or any other treatments other than
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
toolbar.setNavigationIcon(getActionBarIconResource());
so, why toolbar is getting the app primary color? how can i get a transparent toolbar ..any help please?
Thanks in advance
<android.support.v7.widget.Toolbar
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
Check how u style is applied
Where u set it to transparent (alpha?)
View.getBackground().setAlpha(..) ;