Tab background is not there in programmatically - java

How to set the tab background color dynamically? I had tried to get the app:tabBackground="#drawable/tab_background" in the java code but I can't find please help me out friends I am using design library by google I had tried the custom view in the tab layout it worked but the gap is coming in between the tabs
My code
icon_tabs.addTab(icon_tabs.newTab().setCustomView(R.layout.first_tab), true);
icon_tabs.addTab(icon_tabs.newTab().setCustomView(R.layout.second_tab));
icon_tabs.addTab(icon_tabs.newTab().setCustomView(R.layout.third_tab));
icon_tabs.addTab(icon_tabs.newTab().setCustomView(R.layout.fourth_tab));
icon_tabs.addTab(icon_tabs.newTab().setCustomView(R.layout.five_tab));
My Layout for custom tab
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:orientation="vertical">
<FrameLayout
android:id="#+id/first_ll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/first_tab_drawable">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:src="#drawable/love_home" />
</FrameLayout>
</FrameLayout>

Related

How can show bottom navigation view at a top of the app?

I want to show the bottom navigation view at the top of my app like facebook, i try this but its not showing anything.
Use TabLayout and you will have something like that.
Here below is a video which I think it will help you.
You need to use Fragments and TabLayout
https://codinginflow.com/tutorials/android/tab-layout-with-fragments
It does not matter where the bottom navigation view is placed, you can just place it at top of your layout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
app:itemIconTint="#color/bottom_navigation_colors"
app:itemTextColor="#color/black"
app:menu="#menu/bottom_navigation_menu"
app:labelVisibilityMode="labeled"/>
<androidx.viewpager.widget.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>

ScrollView not Scrolling when keyboard shown

This is resizing when the keyboard is showing instead of scrolling. Why is that?
I have adjustResize set in the Manifest but it still isnt scrolling. What else do I need to change? I have tried removing isScrollableView also.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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:background="#color/night"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
android:isScrollContainer="true">
<ImageView
android:id="#+id/iv_login_logo"
android:layout_width="#dimen/login_logo_width"
android:layout_height="#dimen/login_logo_height"
android:src="#drawable/travelbank_logo_white"
android:layout_marginTop="#dimen/login_logo_margin"
android:layout_marginBottom="#dimen/login_logo_margin"/>
<!--Tab Layout-->
<android.support.design.widget.TabLayout
android:id="#+id/tl_login_tabs"
android:layout_width="match_parent"
android:layout_height="#dimen/tab_layout_height"
app:tabGravity="fill"
tabMode="fixed"
app:tabTextAppearance="#style/NavigationTabTextAppeareance"
app:tabIndicatorHeight="0dp"
app:tabPadding="0dp"/>
<!--Login Page-->
<android.support.v4.view.ViewPager
android:id="#+id/vp_login_view_pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</ScrollView>
Turns out you cant have a View Pager inside a Scroll View. I removed the View Pager and everything works fine

What can i use instead of a Sliding drawer

im making a launcher app. in the tutorial it uses a Sliding Drawer which deprecated in Api 17. what could i use instead of this? i tried using the Slideup Panel from one of the posts on here link Below to the gitHub below
gitHubLinkhttps://github.com/umano/AndroidSlidingUpPanel
. but it wont allow me to use it in the way i want. i want the apps to appear in the drawer not in the main content. for some reason the second view only allows me to create a Text view which is for the handle to slide it up. any advice on what other methods i could implment to do the same job. it must slide up from the bottom. thanks for all the help
Ok guys Sussed it. Using The GitHub I posted in the question. what it did is because im aloud as many layouts as i like but only 2 children. i used a relative layout as my first layout with a gridView for my homescreen apps inside and closed it off. then i used anther Relative Layout Below with a textview inside then another Relative layout set with 80dp Padding at the top (the Size of my Text Handle) inside this one i had another gridview for my apps and closed it all off.
the Xml for it looks like this
<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" tools:context=".MainActivity"
android:id="#+id/Mainlayout"
>
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="#+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoPanelHeight="80sp"
sothree:umanoShadowHeight="4dp"
sothree:umanoDragView ="#+id/dragView"
sothree:umanoScrollableView="#+id/list"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/content1"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="50dp"
android:horizontalSpacing="50dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:clickable="true"
>
</GridView>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/handle"
android:text="b"
android:textSize="80sp"
android:textColor="#17ff1c"
android:gravity="center|top"
android:clickable="true" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="80sp"
android:id="#+id/dragView"
android:clickable="true"
android:focusable="false">
>
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="80sp"
android:id="#+id/content"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="50dp"
android:horizontalSpacing="50dp"
android:stretchMode="columnWidth"
android:gravity="center"
>
</GridView>
</RelativeLayout>
</RelativeLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
</RelativeLayout>

How to set specific height at run time for Sliding layout?

I am building an app that uses this library:https://github.com/umano/AndroidSlidingUpPanel to create a panel that slides on from the bottom of the screen when a user clicks an item in a listview.
However i dont want the slide up panel to take up the entire screen. I need there to be a gap at the top, between the panel and the action bar, of exactly 80dp.
I have tried everything i can think of (putting a spacer there with a transparant background, using layoutParams (gives error), etc). But nothing seems to work.
If someone could give me some suggestions as to what i could try next, i would much appreciate it.
The xml layouts are below.
Thanks for your time.
Corey
<com.bacon.corey.audiotimeshift.SlidingUpPanelLayout xmlns:sothree="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:panelHeight="68dp"
sothree:shadowHeight="4dp"
sothree:overlay="true">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:padding="4dip"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:padding="4dip"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1">
</android.support.v4.view.ViewPager>
</LinearLayout>
<com.bacon.corey.audiotimeshift.FloatingActionButton
android:id="#+id/fabbutton"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_gravity="bottom|right"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
app:colour="#color/holo_red_light"
app:drawable="#drawable/ic_content_new"
/>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|top"
android:textSize="16sp"
android:id="#+id/slideUpPanel"
android:background="#android:color/transparent"
>
<fragment android:name="com.bacon.corey.audiotimeshift.PlayFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/fragment_play"
/>
</FrameLayout>
</com.bacon.corey.audiotimeshift.SlidingUpPanelLayout>
What about wrapping your SlidingUpPanelLayout in another layout, say FrameLayout and adding some good old paddingTop to the latter?
I have found a workaround. Draw the background of the pane transparent and put a padding top, but first the library must be modified like it's written here:
https://github.com/umano/AndroidSlidingUpPanel/issues/4
Hope this helps somebody in the future :)

HorizontalScrollView swipe/fling guesture listener

I know this is a common question , but I am completely messed with those different examples and tutorials available on the web.
I have a horizontalScrollView where I add some view dynamically , and I want to set a guestureListener for swiping through the Views . Each view's with is equal to the width of the screen.
You can use the View Pager instead of the horizontalScrollView. http://developer.android.com/reference/android/support/v4/view/ViewPager.html
To keep the View pager at half the screen use something like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/White"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.5">
<android.support.v4.view.ViewPager
android:id="#+id/pagerPromo"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.viewpagerindicator.CirclePageIndicator
android:id="#+id/indicatorPromo"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="5dp"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="vertical">
This View Pager has a circle indicator at the bottom but you can remove that if you like. Just play around with the weights and see what works best for you.

Categories