Why background and buttons cause running slow? - java

When i change the background and buttons of my android project,it really runs slow.It runs too fast using blue background and buttons but it runs too slow when using metal background and silver buttons.why?How can i run much faster using metal background and silver buttons?
Blue background-runs fast
Metal background-runs slow
xml files of metal background buttons
BUTTON DESIGN 1
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:startColor="#AFAFAF"
android:angle="90"
android:type="linear"
/>
<corners
android:radius="5dp"
/>
<stroke
android:color="#AFAFAF"
android:width="5dp"
/>
</shape>
BUTTON DESIGN 2
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:startColor="#FFFFFF"
android:angle="90"
android:type="linear"
/>
</shape>
BUTTON SELECTOR
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/button_design"
android:state_pressed="true"
/>
<item android:drawable="#drawable/button_design2"
/>
</selector>

Related

How to create a custom circular seekbar with custom thumb?

Im trying to create a custom circular seekbar like this one:
I have the shape and the thumb xml done but the thumb isn't appearing when i put it in the layout xml.
Seekbar background xml (lap_counter.xml):
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="rectangle"
android:thicknessRatio="16"
android:useLevel="false">
<corners android:radius="500dp" />
<stroke
android:width="45dp"
android:color="#color/blue_secondary" />
</shape>
</item>
</layer-list>
Custom thumb xml:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#color/white">
<item>
<shape android:shape="oval">
<solid android:color="#color/white"/>
<stroke android:color="#color/orange" android:width="3dp"/>
<size android:width="30dp" android:height="30dp"/>
</shape>
</item>
</layer-list>
But when apply the custom xml this are the results:
<androidx.appcompat.widget.AppCompatSeekBar
android:id="#+id/sb_lap_counter"
android:layout_width="700dp"
android:layout_height="300dp"
android:layout_centerInParent="true"
android:progress="50"
android:background="#drawable/lap_counter"
android:thumb="#drawable/lap_counter_thumb"
tools:progress="50" />
I tried putting it in as a custom style in themes.xml but it doesn't work either.
What am i doing wrong?
You are using a seekbar.This only works for horizontal seeks.That orange thing is the thumbnail which you need.

Android seekbar customize

I am trying to customize and android seekbar (using API 17) so that the whole progress bar line is blue.
I have created the following XML in res/drawable:
draw_seekbar_settings.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<clip>
<shape
android:shape="line">
<stroke
android:color="#color/progressFxBar"
android:width="2dp"
/>
</shape>
</clip>
</item>
</selector>
and
<SeekBar
android:id="#+id/t_seekbar"
android:layout_width="220dp"
android:layout_height="35dp"
android:layout_centerHorizontal="true"
android:max="100"
android:progress="50"
android:progressDrawable="#drawable/draw_seekbar_settings"
The problem is only half the progress bar is blue, the other half doesn't have any colour whatsoever.
I would like to get this image
Instead I am getting this
change the draw_seekbar_settings.xml as follows:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Define the background properties like color etc -->
<item android:id="#android:id/background">
<shape
android:shape="line">
<stroke
android:color="#color/progressFxBar"
android:width="2dp"
/>
</shape>
</item>
<!-- Define the progress properties like start color, end color etc -->
<!-- if you want to change the progress edit following -->
<item android:id="#android:id/progress">
<clip>
<shape>
<gradient
android:startColor="#007A00"
android:centerColor="#007A00"
android:centerY="1.0"
android:endColor="#06101d"
android:angle="270"
/>
</shape>
</clip>
</item>
</layer-list>

Button color change when button pressed

I have been trying over an hour to make a button's color change when I click the button.
Here is my "mybutton.xml"
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#c4161616"
android:endColor="#c4161616"
android:angle="270" />
<corners
android:radius="10dp" />
<stroke
android:width="5px"
android:color="#00FF00" />
</shape>
Now the Button looks like this:
And when the button gets pressed it should look like this:
<gradient
android:startColor="#c4161616"
android:endColor="#c4565656"
android:angle="270" />
I'm a beginner in Android and XML. Can you please show me how to do it?
Bro try this:-
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/button_pressed_yellow"
android:state_pressed="true" />
<item android:drawable="#drawable/button_focused_orange"
android:state_focused="true" />
<item android:drawable="#drawable/button_normal_green" />
</selector>

Android How can i make a gradient of this EditText

This colour code is given to me:
background-image:-moz-linear-gradient(53% 0% -90deg,rgb(255,255,255) 0%,rgb(204,204,204) 100%);
background-image:linear-gradient(-90deg,rgb(255,255,255) 0%,rgb(204,204,204) 100%);
width:787px;
height:142px;
border-color:rgb(221,221,221);
border-width:1px;
border-style:solid;
And ask for this this is a preview
I try This code in my background of edittext
<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_edittext.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#FFFFFF"/>
<corners
android:bottomRightRadius="20dp"
android:bottomLeftRadius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp"/>
<gradient
android:startColor="#ffcccccc"
android:centerColor="#e7e7e8"
android:type="linear"
android:endColor="#ffcccccc"
android:angle="90" />
<stroke android:color="#ffdddddd"
android:width="2dp"/>
</shape>
Now I want same as picture but i cant get It.
How can i set this ?
This the right code for getting gradient.
<gradient android:startColor="#ffcccccc"
android:type="linear"
android:centerColor="#e7e7e8"
android:endColor="#fff5f5f6"
android:angle="90" />

Android Shape Rectangle with 2 colors

I need to make a custom rectangle that should use hex colors from #bff54a up to #88c010.
Actually I have this xml but I can only use one of those colors. How can I make the gradient possible? I already searched and I didn't found anything like this.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="1dp"
android:color="#color/gray_light" />
<solid android:color="#88c010" />
<corners
android:bottomLeftRadius="8dp"
android:bottomRightRadius="8dp"
android:topLeftRadius="8dp"
android:topRightRadius="8dp" />
</shape>
Thanks to all!
Use Gradient as the color of the Drawable :
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="1dp"
android:color="#color/gray_light" />
<gradient
android:type="linear"
android:centerX="0"
android:centerY="1"
android:startColor="#bff54a"
android:endColor="#88c010" />
<corners
android:bottomLeftRadius="8dp"
android:bottomRightRadius="8dp"
android:topLeftRadius="8dp"
android:topRightRadius="8dp" />
</shape>
See Drawable Resources
You can create file shape and implement this code
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangule"> <!-- oval -->
<gradient
android:startColor="#388E3C"
android:endColor="#448AFF"
android:centerColor="#color/colorPrimary"
/>
</shape>
</item>
</selector>
Result

Categories

Resources