I have got a horizontal recyclerView which use horizontal custom scrollbars but i have an issue, thumb is over than the track, how can i specify the width of track for scrollbar?
here is my RecyclerView:
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/itemRecyclerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:scrollbars="horizontal"
app:layoutManager=".LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/skinName2"
android:scrollbarAlwaysDrawHorizontalTrack="true"
android:scrollbarThumbHorizontal="#drawable/scrollbar_horizontal_thumb"
android:scrollbarTrackHorizontal="#drawable/scrollbar_horizontal_track"
tools:itemCount="15"
tools:listitem="#layout/item_item" />
Here is my custom thumb:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:gravity="center_vertical"
android:height="1dp">
<shape
android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>```
and here is my track
```<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:gravity="center_vertical"
android:height="1dp">
<shape
android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
issue is here
Any ideas?
Related
It seems like all my button in my app are getting their color from the theme and not from the drawable that I set. in the xml to the left of the line number it displays the right color and even in the drawable it also displays the right color.
Drawable
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape android:shape="oval">
<solid android:color="#color/LightBlue"/>
<size android:width="120dp" android:height="120dp"/>
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="oval">
<solid android:color="#color/Green"/>
<size android:width="120dp" android:height="120dp"/>
</shape>
</item>
<item >
<shape android:shape="oval">
<solid android:color="#color/Green"/>
<size android:width="120dp" android:height="120dp"/>
</shape>
</item>
</selector>
XML (I only added one button to save space)
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:background="#color/AntiqueWhite"
tools:context=".SecondScreen">
<Button
android:id="#+id/btTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:background="#drawable/roundbutton_top"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/btRight"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Screenshot
Change from Button to androidx.appcompat.widget.AppCompatButton
Try this
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/btTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:background="#drawable/roundbutton_top"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
I want to give gradient to this view like around 10% of imageview at top , transparent center with 70% and 30% gradient at the bottom.
How i can achieve this
Instead of just using a shape with a gradient use a layer-list with 2 gradients with specified height for each
API 21
The android:bottom , android:top attributes represent the padding for the layer list, change these to change the percentage of the gradient to show
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:bottom="690dp"
android:gravity="top">
<shape android:shape="rectangle" >
<gradient
android:angle="270"
android:type="linear"
android:endColor="#android:color/transparent"
android:startColor="#000000" />
</shape>
</item>
<item
android:top="610dp"
android:gravity="bottom">
<shape android:shape="rectangle" >
<gradient
android:angle="270"
android:type="linear"
android:endColor="#000000"
android:startColor="#android:color/transparent" />
</shape>
</item>
If your minSDK is 23+ then it's more easier to specify the height for each layer type
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:height="40dp"
android:gravity="top">
<shape android:shape="rectangle">
<gradient
android:angle="270"
android:endColor="#android:color/transparent"
android:startColor="#000000"
android:type="linear" />
</shape>
</item>
<item
android:height="70dp"
android:gravity="bottom">
<shape android:shape="rectangle">
<gradient
android:angle="270"
android:endColor="#000000"
android:startColor="#android:color/transparent"
android:type="linear" />
</shape>
</item>
Then just apply this as the background of your ViewPager
Try this out, hope this solves your issue
top_gradient:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="270"
android:centerColor="#android:color/transparent"
android:centerY="0.1"
android:startColor="#000000" />
</shape>
bottom_gradient:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="90"
android:centerColor="#android:color/transparent"
android:centerY="0.3"
android:startColor="#000000" />
</shape>
background:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/bg" />
<item android:drawable="#drawable/bg2" />
</layer-list>
gradient.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#00000000"
android:centerColor="#00000000"
android:endColor="#color/primaryTextColor"
android:angle="270"
android:centerY="0.7"
android:dither="true"
android:type="linear"
/>
</shape>
layout.xml:
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/bottomConstraint"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="bottom"
android:background="#drawable/gradient">
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/tvTitle"
style="#style/TextStyleNormal.Large.Bold.White"
android:paddingHorizontal="#dimen/padding_large"
android:paddingTop="#dimen/padding_medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="#+id/bottomConstraint"
app:layout_constraintTop_toTopOf="#+id/bottomConstraint"
tools:text="System Solution to Online Education:
Look To Northeast communal." />
</androidx.constraintlayout.widget.ConstraintLayout>
This will have transparent view but in bottom the gradient would be dark .
You can achieve it like this
gradient_top.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#2B3135"
android:centerColor="#2B3135"
android:endColor="#android:color/transparent"
android:angle="270"
android:centerY="0.1"
/>
</shape>
gradient_bottom.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#2B3135"
android:centerColor="#2B3135"
android:endColor="#android:color/transparent"
android:angle="90"
android:centerY="0.3"
/>
</shape>
layout.xml
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="200dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/ib"/>
<View
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_alignParentTop="true"
android:background="#drawable/gradient_top"/>
<View
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:background="#drawable/gradient_bottom"/>
</RelativeLayout>
Can I change the height of "progress line" in ProgressBar in Android, so it's larger than the "background line" to achieve this effect?
I have tried setting size on background and progress items on my custom progressBarDrawable, but doesn't seem to work.
<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="false"
android:max="100"
android:progress="50"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:progressDrawable="#drawable/xml_progress_bar_line"
style="#style/Widget.AppCompat.ProgressBar.Horizontal"/>
Here is the xml_progress_bar_line.xml file.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<shape>
<size
android:height="5dp"/>
<solid
android:color="#color/grey" />
</shape>
</item>
<item
android:id="#android:id/progress">
<clip>
<shape>
<size
android:height="10dp"/>
<solid
android:color="#color/green" />
<corners
android:radius="10dp"/>
</shape>
</clip>
</item>
</layer-list>
Yes you can do it with add android:top & android:bottom like this:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background" android:top=2dp android:bottom=2dp>
<shape>
<size
android:height="5dp"/>
<solid
android:color="#color/grey" />
</shape>
</item>
<item
android:id="#android:id/progress">
<clip>
<shape>
<size
android:height="10dp"/>
<solid
android:color="#color/green" />
<corners
android:radius="10dp"/>
</shape>
</clip>
</item>
Change the maxHeight and minHeight to equal each other, then set the layout_heightexplicitly.
Also try using #android:style/Widget.ProgressBar.Horizontal
You can also set vertical scale - mProgressBar.setScaleY(3f);
Here's an example I took from: https://xinyustudio.wordpress.com/2014/08/19/android-change-progressbar-height/
I ended up not using the progress bar at all!
I just used 2 lines in relative layout. Here is the corresponding code!
Here is the progress bar background line xml (xml_custom_progress_bar_bg.xml):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners
android:radius="4dp"/>
<solid
android:color="#color/light_grey"/>
</shape>
Here is the progress bar "progress line" xml (xml_custom_progress_bar_progress.xml):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners
android:radius="4dp"/>
<gradient
android:angle="270"
android:startColor="#color/green"
android:endColor="#color/green"/>
</shape>
And here is the progress bar container:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_centerVertical="true"
android:background="#drawable/xml_custom_progress_bar_bg"/>
<View
android:layout_width="0dp"
android:layout_height="8dp"
android:layout_centerVertical="true"
android:background="#drawable/xml_custom_progress_bar_progress"/>
</RelativeLayout>
Then, I calculate the progress manually and set the width of "progress line" programmatically.
I'm struggling to add a shadow to my custom overlay button over the google map. My goal is to make my custom button look just like Google's MyLocation button. Here's how my app looks like now:
layout.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
style="#style/AppTheme">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/map"
tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true" />
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/button"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:src="#drawable/ic_search_black_24dp"
android:tint="#color/icon_gray"
android:onClick="searchButtonClicked"
android:background="#drawable/mapbutton"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.quinny898.library.persistentsearch.SearchBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/searchbox"
/>
</LinearLayout>
</RelativeLayout>
mapbutton.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false">
<shape android:shape="rectangle">
<corners android:radius="1.3dp" />
<solid android:color="#55FFFFFF" />
</shape>
</item>
<item
android:state_pressed="true"
android:state_enabled="true">
<shape android:shape="rectangle">
<corners android:radius="1.3dp" />
<solid android:color="#ccb3b3b3" />
</shape>
</item>
<item
android:state_focused="true"
android:state_enabled="true">
<shape android:shape="rectangle">
<corners android:radius="1.3dp" />
<solid android:color="#A9FFFFFF" />
</shape>
</item>
<item android:state_enabled="true">
<shape android:shape="rectangle">
<corners android:radius="1.3dp" />
<solid android:color="#baffffff" />
</shape>
</item>
</selector>
I have already tried changing the android:elevation value on the ImageButton. Unfortunately, adding elevation value doesn't seem to add a shadow to the button. Is there a way to add a shadow to my mapbutton drawable?
From here what worked for me was:
<ImageButton
android:clipToPadding="false"
android:outlineProvider="bounds"
android:elevation="2dp" />
Try this code
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item android:left="5dp" android:top="5dp">
<shape>
<corners android:radius="3dp"/>
<solid android:color="#D6D6D6"/>
</shape>
</item>
<item android:bottom="2dp" android:right="2dp">
<shape>
<gradient android:angle="270" android:endColor="#DC5F0A" android:startColor="#E68F54"/>
<!--
<stroke android:width="1dp" android:color="#BABABA" />
-->
<corners android:radius="4dp"/>
<padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp"/>
</shape>
</item>
</layer-list>
</item>
</selector>
I hope it will.
I wanted to add a linear layout, having a transparent background as well as with white borders. The problem is: as far as I have googled, I can achieve only one out of both.
Here's what I did:
Saved the following as border.xml in drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
<item android:left="5dp" android:right="5dp" android:top="5dp" android:bottom="5dp" >
<shape android:shape="rectangle">
</shape>
</item>
</layer-list>
my existing page layout
<LinearLayout
android:id="#+id/quiz"
android:layout_width="150dp"
android:layout_height="120dp"
android:background="#66041414" <-------- replaced it with android:background="#drawable/border"
android:orientation="vertical"
android:layout_marginLeft="5dp" >
......
</LinearLayout>
I am getting opaque background, when the border was included.
I wanted a final result to be like:
totally stuck with it. Just wanted to find a way out to achieve it. Any suggestions would be quite helpful.
Your drawable for background of layout:
You can change radius for corner shape if you want. But stroke will create a border and solid part is the background which we are making transparent.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="2dp"
android:topRightRadius="0dp"
android:bottomRightRadius="0dp"
android:bottomLeftRadius="0dp" />
<stroke
android:width="1dp"
android:color="#android:color/white" />
<solid android:color="#android:color/transparent"/>
</shape>
and my test layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ll1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/ll2"
android:layout_height="50dp"
android:layout_width="50dp"
android:background="#drawable/my_transparent_linear_layout"></LinearLayout>
</LinearLayout>
It works, Below is the proof:
For this you can use two layout aligned one top of the other then set the background transparent for the top view and set the white border as background for the bottom view. You can do this thing inside relative layouts.
Xml Drawable for background:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="30dp" />
<stroke android:width="5dp" android:color="#ffffffff"/>
<solid android:color="#66000000"/>
</shape>
Adjust radius, width and dark color transparency ( #ff and #66 parts) as you please.
Indeed well suggestion by #Ali Imran, check below way, hope it will help.
back.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<stroke android:width="1dp" android:color="#dd7b7a"/>
<corners android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp" android:topRightRadius="10dp"/>
<solid android:color="#dd7b7a"/>
</shape>
main.xml
<?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"
android:gravity="center"
>
<LinearLayout
android:padding="4dip"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/back"
android:gravity="center_horizontal"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/tile_mode" // your transparent image
/>
</LinearLayout>
</LinearLayout>
also go through below links in that, way of using xml will works for you.
Bitmap image with rounded corners with stroke