I am trying to add some margin to the scrollbar inside of an editText but I am not sure how to do that, given the scrollbar is inside of the editText itself ("scrollbars=horizontal"). The way it comes automatically is too close to the text and I need it to be farther away, is there a way to do that?
I have a custom style for the scrollbar and it already looks the way it does in the picture, except for the distance, maybe there's a way to adjust the margins there? So far, only the right margin works, the top and bottom one make the bar disappear.
It needs to look like this:
XML:
<EditText
android:id="#+id/edit_text"
style="#style/Field"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/size_2"
android:layout_marginTop="#dimen/size_1"
android:layout_marginBottom="#dimen/size_1"
android:autofillHints="#null"
android:clickable="true"
android:duplicateParentState="true"
android:focusable="true"
android:inputType="text"
android:scrollbars="horizontal"
android:scrollbarStyle="outsideOverlay"
android:scrollbarThumbHorizontal="#drawable/scrollbar"
android:scrollbarTrackHorizontal="#drawable/scrollbar_track"
android:gravity="center_vertical"/>
Scrollbar thumb:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:right="16dp"> <!-- Margin -->
<shape>
<solid android:color="#color/specific_border_2" />
<corners android:radius="4dp" />
</shape>
</item>
</layer-list>
Scrollbar track:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:right="16dp"> <!-- Margin -->
<shape>
<solid android:color="#E2E0EB" />
<stroke
android:width="1dp"
android:color="#color/specific_background_3" />
<size android:width="15dp" />
<corners android:radius="4dp" />
</shape>
</item>
</layer-list>
You can set android:scrollbarStyle="outsideOverlay" and control the margin of the scrollbar using android:paddingBottom
Demo:
<EditText
android:id="#+id/name_text"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:fadeScrollbars="false"
android:paddingBottom="8dp"
android:scrollbarAlwaysDrawHorizontalTrack="false"
android:scrollbarStyle="outsideOverlay"
android:scrollbarThumbHorizontal="#drawable/scrollview_thumb"
android:scrollbars="horizontal" />
scrollview_thumb.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#C2C3C3" />
<corners android:radius="15dp" />
<size android:width="5dp" />
</shape>
Related
I try to put a border for a button in android but unfortunately I can't see the button border.
Drawable File 👇
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="12dp" />
<stroke android:width="3px" android:color="#7E8082" />
</shape>
</item>
</selector>
XML 👇
<Button
android:id="#+id/btn_signup"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="122dp"
android:background="#drawable/bg_signup"
android:fontFamily="#font/poppins_semibold"
android:text="Create an Account"
android:textAllCaps="false"
android:textColor="#color/black"
app:layout_constraintTop_toBottomOf="#+id/btn_login" />
You don't need to use a custom drawable, just use a MaterialButton:
<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/Widget.MaterialComponents.Button.OutlinedButton"
app:strokeColor="#7E8082"
app:strokeWidth="1dp"
app:cornerRadius="12dp"/>
Don't use a selector for single option use shape directly
bg_signup
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#cdcdcd"/>
<corners
android:radius="4dp"
/>
<stroke
android:width="1dp"
android:color="#000"
/>
</shape>
use Style attribute instead of android:background="#drawable/bg_signup"
make a custom style then call it android:style="#style/bg_signup"
I have a button
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="45dp"
android:onClick="loginIsClicked"
android:layout_marginStart="8dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="8dp"
android:background="#drawable/button"
android:text="#string/Auth"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="16sp"
android:enabled="false" />
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/red"/>
<corners android:radius="10dp"/>
</shape>
How can I add animation to the button used in the default buttons?
Example:
enter image description here
If I understood correctly, what you are looking for is a ripple. Wrap your shape in a ripple as follows and provide your ripple color:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#color/rippleColor">
<item>
<shape android:shape="rectangle">
<solid android:color="#color/red"/>
<corners android:radius="10dp"/>
</shape>
</item>
</ripple>
Add MaterialButton.
<com.google.android.material.button.MaterialButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Button" />
Also do not forget to change theme Theme.AppCompat.Light.DarkActionBar to Theme.MaterialComponents.Light.DarkActionBar in styles.xml file.
I have a border that I made for a button that should be enabled when the button is clicked on.
<Button
android:id="#+id/imageView_red"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:src="#drawable/border" />
My question is how can I enable/disable this drawable? Does java provide a solution for this?
I tried looking at this post, but it didn't seem to answer that question
Android - border for button
All you need to do is you have to put the selector drawable in the button like this
<Button
android:id="#+id/button1"
android:background="#drawable/selector_xml_name"
android:layout_width="200dp"
android:layout_height="126dp"
android:text="Hello" />
And the drawable like this
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<stroke android:width="10dp"/>
</shape>
</item>
<item android:state_pressed="false">
<shape>
<stroke android:width="0dp"/>
</shape>
</item>
I have a searchview and i changed the edittext box of them with a drawable (with java code). However I have a mysterious border that i can't remove. If you see the screenshot you will see the red line that is a border defined in drawable 'editext.xml' My problem is I doesn't know what is the black line arround the edittext. Anybody know what is and how i remove it?
drawable (edittext):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="1dip" android:color="#c66262" />
<solid android:color="#FFFFFF" />
</shape>
drawable (searchview):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:padding="10dp">
<solid android:color="#FFFFFF"/>
<stroke android:width="1dip" android:color="#000000" />
<corners
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>
</shape>
acitivty 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:fitsSystemWindows="true"
tools:context=".SearchActivity" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="160sp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#drawable/search_background"
android:orientation="vertical" >
<SearchView
android:id="#+id/searchView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20sp"
android:layout_marginRight="20sp"
android:layout_marginTop="60sp"
android:actionViewClass="android.widget.SearchView"
android:background="#drawable/searchview"
android:fitsSystemWindows="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:iconifiedByDefault="false"
android:paddingLeft="10sp"
android:paddingTop="5sp"
android:showAsAction="collapseActionView" >
</SearchView>
</LinearLayout>
</RelativeLayout>
ScreenShot: http://imageshack.com/a/img842/6100/ebsb.jpg
thanks in advance
I think your red color is set in this line in your edittext shape:
<stroke android:width="1dip" android:color="#c66262" />
maybe set here:
<stroke android:width="1dip" android:color="#000000" />
for a black stroke
Edit: this is for making red line black. I misunderstood question a bit. Anyhow I think would look nicer this way. My few cents ;-)
Anyhow, if you don't want the black line, then just set the black line (#000000) to let's say white:
<stroke android:width="1dip" android:color="#ffffff" />
or simply get rid of it at all, by just deleting this code here, which looks like it is your black stroke:
<stroke android:width="1dip" android:color="#000000" />
<corners
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>
Just remove following line from drawable(searchview):
stroke android:width="1dip" android:color="#000000"
I'm trying to create buttons in Android the same way as in Jeepsing application for iPhone using linear layout but without success. Maximum that I get is three separated buttons the same size.
I need three buttons without background, separated only by their borders when two of them have one rounded corner like on the following screenshot:
This is my last try:
<LinearLayout android:id="#+id/LinearLayout02" android:layout_height="wrap_content" android:layout_width="match_parent">
<Button android:id="#+id/Button04" android:text="Button" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content"></Button>
<Button android:id="#+id/Button05" android:text="Button" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content"></Button>
<Button android:id="#+id/Button06" android:text="Button" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content"></Button>
</LinearLayout>
I also tried GridLayout but without success.
just create shapes with corners radius for both pressed/released effects..
<solid android:color="#77000000" />
<corners android:radius="10dip" />
<gradient
android:angle="-90"
android:endColor="#44FF0000"
android:startColor="#CCFF0000" />
<padding
android:bottom="10dip"
android:left="10dip"
android:right="10dip"
android:top="10dip" />
<stroke
android:width="1dip"
android:color="#000000" >
</stroke>
for more info about shapes refer this
After creating shapes for pressed/released effects create a XML file for button selector like following example
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="#drawable/prs_arrival_fb_btn" /> <!-- pressed -->
<item
android:state_focused="true"
android:drawable="#drawable/prs_arrival_fb_btn" /> <!-- focused -->
<item
android:drawable="#drawable/arrival_fb_content_btn" /> <!-- default -->
</selector>
then set this selector to your button as background.. like the following example..
<Button android:text="Play" android:id="#+id/playBtn"
android:background="#drawable/button_selector"
android:textColor="#ffffff" />
This is how I achieved it:
up_left_button_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/up_left_button_shape_pressed"
android:state_pressed="true" />
<item android:drawable="#drawable/up_left_button_shape_pressed"
android:state_selected="true" />
<item android:drawable="#drawable/up_left_button_shape_released" />
</selector>
up_left_button_shape_pressed.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#ff0000ff"
android:endColor="#ff0000ff"
android:angle="45"/>
<padding android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp" />
<corners android:radius="8dp"
android:bottomRightRadius="0dp" android:bottomLeftRadius="0dp"
android:topLeftRadius="8dp" android:topRightRadius="0dp"/>
<stroke android:width="2dp" android:color="#ff444444"/>
</shape>
up_center_button_shape_released.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#00000000"
android:endColor="#00000000"
android:angle="45"/>
<padding android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp" />
<corners android:radius="8dp"
android:bottomRightRadius="0dp" android:bottomLeftRadius="0dp"
android:topLeftRadius="8dp" android:topRightRadius="0dp"/>
<stroke android:width="2dp" android:color="#ff444444"/>
</shape>
Center and right button shapes are the same, just need to play with which corners to round.
And finally the view layout:
<TableRow android:id="#+id/buttonsRow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp">
<RelativeLayout android:id="#+id/buttonsRowRelativeLayout"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<Button
android:id="#+id/leftButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/save"
android:textColor="#ffffffff"
android:background="#drawable/up_left_button_selector"
android:layout_toLeftOf="#+id/centerButton" />
<Button
android:id="#+id/centerButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/change"
android:textColor="#ffffffff"
android:background="#drawable/up_center_button_selector"
android:layout_centerHorizontal="true"/>
<Button
android:id="#+id/rightButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/send"
android:textColor="#ffffffff"
android:background="#drawable/up_right_button_selector"
android:layout_toRightOf="#+id/centerButton" />
</RelativeLayout >
</TableRow>
And it looks pretty good.