I'm trying to create my own style for the ProgressBar, but I can't get the desired result.
<ProgressBar
android:id="#+id/indicator"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="50dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
style="?android:attr/progressBarStyleHorizontal"
android:background="#drawable/myprogressbar"
android:progress="0"/>
Style (tried many options from the most primitive to more complex):
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<color android:color="#2ecc71"></color>
</item>
<item android:id="#android:id/progress">
<clip>
<color android:color="#27ae60"></color>
</clip>
</item>
</layer-list>
enter image description here
As a result, I look like this:
Either the bar area is higher than the height of the ProgressBar itself
Or the area is equal to the ProgressBar, a thin line cannot be made higher. What am I doing wrong and how to fix it?
The bar area height is not equal to the ProgressBar height because the height of the ProgressBar is determined by its android:layout_height attribute, while the height of the bar area is determined by the height of the items in the layer-list drawable.
To fix this, you can increase the height of the items in the layer-list drawable.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background" android:height="50dp">
<color android:color="#2ecc71"></color>
</item>
<item android:id="#android:id/progress" android:height="50dp">
<clip>
<color android:color="#27ae60"></color>
</clip>
</item>
</layer-list>
Related
I have 2 buttons ( left and right ) with one background drawable.
The background has corners on the right side.
I don't want to create one more background just for a change the side of the corners to left, so how can I rotate the background with corners on right in the XML file to put the corners on left?
I've tried to add android:rotation="180dp" but it's not worked for me:
<Button
android:background="#drawable/toggle_buttons"
android:id="#+id/btnLogin"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="#string/login"
android:textAllCaps="false" />
<Button
android:background="#drawable/toggle_buttons"
android:id="#+id/btnSignUp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="#string/sign_up"
android:textAllCaps="false" />
code for the drawable background as below
<item>
<shape android:shape="rectangle">
<solid android:color="#color/background_color"/>
<corners android:bottomRightRadius="100dp" android:topRightRadius="100dp"/>
<stroke android:color="#color/text_color" android:width="0.5dp"/>
</shape>
</item>
You don't need a custom background. You can use the standard MaterialButton in the Material Components Library and apply a shapeAppearanceOverlay:
<com.google.android.material.button.MaterialButton
app:strokeWidth="..."
app:strokeColor="#color/...."
app:shapeAppearanceOverlay="#style/left"/>
<com.google.android.material.button.MaterialButton
app:strokeWidth="..."
app:strokeColor="#color/...."
app:shapeAppearanceOverlay="#style/right"/>
with:
<style name="right">
<item name="cornerSize">50%</item>
<item name="cornerSizeBottomLeft">0dp</item>
<item name="cornerSizeTopLeft">0dp</item>
</style>
<style name="left">
<item name="cornerSize">50%</item>
<item name="cornerSizeBottomRight">0dp</item>
<item name="cornerSizeTopRight">0dp</item>
</style>
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 am using spinner in my layout and its appearance is as follows:
I want to increase the spinner size to make it more attractive and visible.
here is spinner xml and activity snippet.
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner_room"
android:layout_below="#id/Toolbar_Room"
android:textSize="52sp"
android:prompt="#string/room_prompt"
android:spinnerMode="dropdown"
android:dropDownSelector="#drawable/img_small_box_green"
android:drawSelectorOnTop="true"></Spinner>
Create a custom layout for your Spinner and inflate it through an adapter.
Check out this.
http://abhiandroid.com/ui/custom-spinner-examples.html
I have created spinner with card view check this you may like this design.
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_5"
android:background="#android:color/white"
app:cardElevation="#dimen/margin_2"
app:contentPaddingBottom="#dimen/margin_5"
app:contentPaddingTop="#dimen/margin_5">
<Spinner
android:id="#+id/sp_filter_status"
style="#style/Widget.Spinner"
android:background="#drawable/spinner_expand_black"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:padding="0dp" />
</android.support.v7.widget.CardView>
drawable/spinner_expand_black
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item>
<shape>
<solid android:color="#android:color/white" />
<padding
android:bottom="#dimen/margin_1"
android:left="#dimen/margin_1"
android:right="#dimen/margin_1"
android:top="#dimen/margin_1" />
</shape>
</item>
<item>
<bitmap
android:gravity="end"
android:src="#mipmap/ic_action_expand_more" />
</item>
</layer-list>
#mipmap/ic_action_expand_more is image of bottom arrow you can find from material icon site.
Style
<style name="Widget.Spinner" parent="Widget.AppCompat.Spinner.DropDown">
<item name="android:background">?android:selectableItemBackground</item>
<item name="android:dropDownSelector">?android:selectableItemBackground</item>
<item name="android:divider">#null</item>
<item name="overlapAnchor">true</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:textSize">#dimen/text_16</item>
<item name="android:focusableInTouchMode">true</item>
<item name="android:focusable">true</item>
</style>
put your Spinner inside CardView.
it will look more better.
I have put an edit text which has a tint color as white. But it looks black in android above 4.0 devices till lollipop.
I searched for this and got solutions as apply background color as white.
But I have another layout from which the edit text belongs which has dark blue color, so if I apply background color as white whole edit text looks white on that dark blue layout.
What can I do for this now?
Layout :
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/purple_bg"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="true"
android:id="#+id/linearLayout"
android:weightSum="1">
<EditText
android:layout_width="match_parent"
android:layout_height="42dp"
android:id="#+id/editTextOrderItem"
android:layout_gravity="center_vertical"
android:backgroundTint="#ffffff"
android:drawableTint="#ffffff"
android:hint="Type here..."
android:textColorHint="#ffffff"
android:paddingLeft="15dp"
android:imeOptions="actionDone"
android:textSize="12sp"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_centerVertical="true"
android:textColor="#ffffff"
android:layout_toLeftOf="#+id/imageViewSearch"
android:layout_toStartOf="#+id/imageViewSearch"
android:singleLine="true" />
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/imageViewSearch"
android:backgroundTint="#android:color/white"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_gravity="center"
android:src="#drawable/btn_search"
android:layout_centerVertical="true"
android:padding="10dp"
android:layout_marginRight="06dp" />
</RelativeLayout>
color.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#ffffff</color>
<color name="colorPrimaryDark">#eeeeee</color>
<color name="colorAccent">#3e3e3e</color>
<color name="black">#747474</color>
<color name="drawerBacground">#e6f7fd</color>
<color name="themetextcolor">#009688</color>
<color name="darktextcolor">#000000</color>
<color name="lighttextcolor">#ACABAC</color>
<color name="activity_bg_color">#D9E7E4</color>
<color name="activity_footer_color">#37b0a0</color>
<color name="btn_text">#b3ffffff</color>
<color name="seperator">#dedede</color>
<color name="accent">#00B0FF</color>
</resources>
Please help, thank you..
EDIT:
I tried to add new theme and put it in activity in manifest, but did not help.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/black</item>
<item name="colorAccent">#color/accent</item>
<item name="android:typeface">monospace</item>
<item name="android:textSize">17sp</item>
</style>
<style name="AppTheme2" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:typeface">monospace</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorPrimary</item>
</style>
<style name="AppTheme1" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:typeface">monospace</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/accent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
Manifest :
<activity android:name=".Activities.MainActivity"
android:theme="#style/AppTheme2"
/>
Create a drawable resource xml file (your requirement is only to have a bottom stroke)
Set givendrawable as the background of the editText then you can add the background color you need + bottom line you need with a color
Explain:
This is a resource drawable
dashGap & dashWidth is for doted/broken lines (remove them if you do not need dashes)
android:top -> you can give minus sizes to the views that you don't need to display.(here your requirement is to show only bottom line so top,right & left lines of the item has given -2dp )
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" >
<solid android:color="#FFF" /> <-- background color here
</shape>
</item>
<item android:top="-2dp" android:right="-2dp" android:left="-2dp">
<shape>
<solid android:color="#android:color/transparent" />
<stroke
android:dashGap="10px"
android:dashWidth="10px"
android:width="1dp"
android:color="#ababb2" <-- bottom line color here />
</shape>
</item>
</layer-list>
you can set different different color accent at activity in your manifest file.
<color name="colorAccent">#FFFFFF</color>
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Add"
android:id="#+id/btnAdd"
android:background="#ff6347"
android:textColor="#f8f8f8"
android:layout_marginTop="36dp"
android:clickable="true"
android:layout_below="#+id/txtAddress"
android:layout_centerHorizontal="true"
android:focusable="true" />
This is my XML Button element and it's fine and dandy...but I want it to be known when it's pressed. How can I go about making it have different styling when pressed vs when not pressed?
You can use a selector and use a drawables for different states.
http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
You can also use OnTouchListener and on ACTION_DOWN and ACTION_UP set the color to the buttons
You want to use a selector as the background for the button. Basically you can define the the different shape you want for each state of the button and the shape consists of color, corner radius, and other cool things.
XML file saved at res/drawable/button.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"> <!-- pressed -->
<shape android:shape="rectangle" >
<solid android:color="#color/blue" />
</shape>
</item>
<item> <!-- default -->
<shape android:shape="rectangle" >
<solid android:color="#color/red" />
</shape>
</item>
</selector>
This layout XML applies the state list drawable to a Button:
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/button" />