I have a circular drawable on which I set a 8dp white stroke, like this:
circleImage = (ImageView) rootView.findViewById(R.id.image);
circleImage.setOnClickListener(clickListener);
drawable = (GradientDrawable) circleImage.getBackground();
drawable.setStroke(8, getResources().getColor(R.color.colorWhite));
The XML for circleImage looks like this:
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_centerInParent="true"
android:id="#+id/image"
android:background="#drawable/roundcorner"
android:clickable="true"/>
What I want to do now is to change the drawable.setStroke to include a gradient color like this
I suppose the easiest way to achieve this is to write something in the drawable XML, but I don't quite know how to achieve this.
roundcorner.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:topLeftRadius="100dp"
android:topRightRadius="100dp"
android:bottomLeftRadius="100dp"
android:bottomRightRadius="100dp"
/>
<padding
android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp"
/>
<size
android:width="100dp"
android:height="100dp"
/>
</shape>
You should do something like this. Use layer-list with 2 shapes. First one is for gradient stroke and second one is for solid.
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="oval" >
<gradient
android:angle="360"
android:startColor="#543456"
android:endColor="#ff00b5"
android:type="linear" />
<size android:width="24dp"
android:height="24dp"/>
</shape>
</item>
<item
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp">
<shape android:shape="oval" >
<solid android:color="#fff" />
</shape>
</item>
</layer-list>
This code looks like this
If you need inner color to be transparent, then you can use a ring shape:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:thickness="2dp"
android:useLevel="false">
<gradient
android:startColor="#color/sea_green"
android:endColor="#color/black"
android:angle="270" />
</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'm trying to make my custom seekbar.
This is what i try to do:
and this is what I succeed to do:
How to add this circles behind my progress?
Here is my code:
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progressDrawable="#drawable/progress"
android:thumb="#drawable/unnamed"
android:id="#+id/risk_seek_bar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
progress.xml
<?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="#00FF0000" />
<padding android:bottom="1dp"/>
</shape>
</item>
<item
android:id="#android:id/background"
android:drawable="#drawable/background_fill"/>
<item android:id="#android:id/progress">
<clip android:drawable="#drawable/progress_fill" />
</item>
</layer-list>
background fill.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="90"
android:centerColor="#FF555555"
android:endColor="#FF555555"
android:startColor="#FF555555" />
<corners android:radius="10dp" />
<stroke
android:width="1dp"
android:color="#50999999" />
<stroke
android:width="1dp"
android:color="#70555555" />
</shape>
progress_fill.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="90"
android:centerColor="#FFFF4400"
android:endColor="#FFFF4400"
android:startColor="#FFFF4400" />
<corners android:radius="10dp" />
<stroke
android:width="1dp"
android:color="#50999999" />
<stroke
android:width="1dp"
android:color="#70555555" />
</shape>
You can use any of the following libraries
range-slider-view
material-range-bar
range-bar
How to change the text color of the keys?
Here is my keyboard layout.
<?xml version="1.0" encoding="UTF-8"?>
<android.inputmethodservice.KeyboardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/keyboard"
android:keyBackground="#drawable/key_background"
android:background="#color/keyboard_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:keyPreviewLayout="#layout/preview" />
key_background.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Bottom 2dp Shadow -->
<item android:top="4dp"
android:left="2dp"
android:right="2dp">
<shape android:shape="rectangle" >
<solid android:color="#color/key_shadow" />
<corners android:radius="4dp"/>
</shape>
</item>
<!-- White Top color -->
<item android:bottom="4px"
android:top="4dp"
android:left="2dp"
android:right="2dp">
<shape android:shape="rectangle" >
<solid android:color="#color/white" />
<corners android:radius="4dp" />
</shape>
</item>
</layer-list>
Please look into this you will get an idea for your problem.
http://developer.android.com/reference/android/inputmethodservice/KeyboardView.html
android:keyTextColor="your color code"
U can use android:keyTextColor attribute: like
android:keyTextColor="#android:color/black"
In my app i need to display toggle button that looks like this (this one is for checked state) http://s58.radikal.ru/i159/1308/dc/e3cb45e9a71f.jpg, dark color is parent view background.
It must be just a colored circle with 50x50 size, but for checked state it must include that blue border outside. The whole button must be always 70x70, so it has enough space for border. I guess i have to use simple shape drawable for default state and layer-list drawable for checked state, but it doesnt work for me, it just creates some kind of stretched oval and without any border(like this http://s019.radikal.ru/i619/1308/50/0f02f9ab2ea4.jpg). Here is the code i'm using for ToggleButton background:
first_board_color_dot.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_checked="true" android:drawable="#drawable/first_board_color_dot_checked"></item>
<item android:drawable="#drawable/first_board_color_dot_default"></item>
</selector>
first_board_color_dot_checked.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape
android:innerRadius="34dp"
android:shape="ring"
android:thickness="2dp" >
<solid android:color="#color/first_player_dot_color" />
</shape>
</item>
<item>
<shape android:shape="oval" android:gravity="center">
<solid android:color="#color/first_board_color" />
<size
android:height="50dp"
android:width="50dp" />
</shape>
</item>
</layer-list>
first_board_color_dot_default.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="oval" android:gravity="center">
<solid android:color="#color/first_board_color" />
<size
android:height="50dp"
android:width="50dp" />
</shape>
</item>
</layer-list>
this is how i'm setting up button
<ToggleButton
android:id="#+id/board_color_button1"
android:layout_width="wrap_content"
android:layout_height="70dp"
android:layout_marginRight="30dp"
android:text=""
android:textOn=""
android:textOff=""
android:background="#drawable/first_board_color_dot"
android:checked="true"
android:onClick="boardColorButtonClicked"/>
i cannot understand what im doing wrong...
i am using following code.
<RelativeLayout
android:layout_width="310dp"
android:layout_height="70dp"
android:layout_below="#+id/UIReportView"
android:layout_marginLeft="4dp"
android:layout_marginTop="2dp"
android:background="#drawable/small_corners" >
small_corners
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/UINoCorners"
android:shape="rectangle">
<corners android:radius="10dp"/>
<padding android:left="10dp"
android:right="10dp"
android:top="5dp"
android:bottom="5dp"/>
<solid android:color="#FFFFFF"/>
</shape>
Now , it shows a white bar. I want that, whenever i click on this relative layout its color should change, set by me.
report = (RelativeLayout) findViewById(R.id.UIMainReportViewTimely);
report .setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
// My Code
}
});
What should i do here? report.onTouchEvent?
And how can i change the color of background.
Best Regards
Create another drawable with the new background, and in your setOnclickListener put
report.setBackgroundDrawable(R.drawable.newbackground_small_corners);
or
report.setBackgroundColor(Color.parseColor("#00000000"));
you can use 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="1dp" android:color="#999999" />
<padding android:left="10dp" android:top="3dp" android:right="10dp"
android:bottom="3dp" />
<corners android:radius="7dp" android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp" android:topLeftRadius="0dp"
android:topRightRadius="0dp" />
<gradient android:startColor="#449def" android:endColor="#2f6699"
android:angle="270" />
</shape>
</item>
<item>
<shape>
<corners android:radius="10dp"/>
<padding android:left="10dp"
android:right="10dp"
android:top="5dp"
android:bottom="5dp"/>
<solid android:color="#FFFFFF"/>
</shape>
</item>
</selector>
</shape>
I'd rather suggest to use the onTouch() method and check whether the touched coordinates are within the bounds of your relative layout. If yes, then just set background using setBackgroundColor().