I'm new to XML language and have no clue on how to put and ImageButton inside a circular progress bar and also have no clue if that's even possible.
No. If you want to customize ProgressBar you need to set Style and android:progressDrawable
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:progressDrawable="#drawable/custom_progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
then you can create Layer-List Drawable or any other drawable.
<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>
<gradient
android:startColor="#000001"
android:centerColor="#0b131e"
android:centerY="1.0"
android:endColor="#0d1522"
android:angle="270"
/>
</shape>
</item>
<!-- Define the progress properties like start color, end color etc -->
<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>
check out this
Related
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>
I am trying to set drawable as an arrow in Spinner but bitmap is not supported.
I used svg file (ic_arrow.xml) and set it in spinner_arrow.xml file:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<padding
android:left="4dp"
android:top="4dp"
android:right="4dp"
android:bottom="4dp"
/>
<solid android:color="#color/white" />
<stroke android:width="2px" android:color="#color/grey" />
<corners android:radius="5dp" />
</shape>
</item>
<item>
<bitmap android:gravity="center|right" android:src="#drawable/ic_arrow"/>
</item>
</layer-list>
So I used it for background in layout file
<Spinner
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/spinner_arrow"/>
But I have an error in displaying Spinner: "Binary XML file line #41 in myapp:layout/activity_registration_driver: Error inflating class Spinner".
I think the problem is in adding drawable for arrow in spinner but i don't know how to solve it
Please use below code for add arrow with spinner:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="#dimen/btn_height_common"
android:layout_marginLeft="#dimen/_15sdp"
android:layout_marginTop="#dimen/_5sdp"
android:layout_marginRight="#dimen/_15sdp"
android:background="#drawable/bg_editext">
<Spinner
android:id="#+id/sp_gender"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#null"
android:entries="#array/gender"
android:fontFamily="#font/gotham_narrow_book"
android:overlapAnchor="false"
android:paddingLeft="#dimen/_10sdp"
android:paddingRight="#dimen/_10sdp"
android:textColor="#color/gray_text_color"
android:textSize="#dimen/normal_textsize" />
<ImageView
android:layout_width="#dimen/_15sdp"
android:layout_height="#dimen/_15sdp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="#dimen/_15sdp"
android:padding="#dimen/_2sdp"
android:src="#mipmap/ic_down_gray" />
</RelativeLayout>
Output:
Basically one needs to create a custom background for a spinner. It should be something like this:spinner_background.xml
<item>
<layer-list>
<item>
<color
android:color="#android:color/white"/>
</item>
<item>
<bitmap
android:gravity="center_vertical|right"
android:src="#drawable/ic_arrow_drop_down_black_24dp"/>
</item>
</layer-list>
</item>
Then create a custom style for your spinner, where you specify the above selector as background:
<style name="Widget.App.Spinner" parent="#style/Widget.AppCompat.Spinner">
<item name="overlapAnchor">true</item>
<item name="android:background">#drawable/spinner_background</item>
</style>
And finally in your app theme you should override two attributes if you want it to be applied all across your app:
<item name="spinnerStyle">#style/Widget.App.Spinner</item>
<item name="android:spinnerStyle">#style/Widget.App.Spinner</item>
I want to achieve this button animation in Android. The sample below is from iOS. I want the shadow to disappear when the user clicks the button and reappear once the user releases the button.
Any help will be highly appreciated.
You need to add color like the following. For example, the color name is button_text_color.xml. Here is the .xml file which needs to be put in the color folder. If the color folder does not exist, create one in your res directory.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#50FFFFFF" android:state_pressed="true" />
<item android:color="#FFFFFF" android:state_pressed="false" />
</selector>
Check that I have added 50% transparency to the white color in the pressed state. Now just add this attribute in the Button where it is declared.
Now you need a background drawable, to be put in your drawable folder. For example, let us take the name of the drawable is button_state_list_animator.xml. This should have the following content.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<layer-list>
<item>
<shape>
<solid android:color="#android:color/darker_gray" />
<corners android:radius="19dp" />
</shape>
</item>
<item android:bottom="5px">
<shape>
<padding android:bottom="5dp" />
<gradient android:angle="270" android:endColor="#163969" android:startColor="#1c4985" />
<corners android:radius="19dp" />
<padding android:bottom="10dp" android:left="10dp" android:right="5dp" android:top="10dp" />
</shape>
</item>
</layer-list>
</item>
<item android:state_pressed="true">
<layer-list>
<item>
<shape>
<solid android:color="#102746" />
<corners android:radius="19dp" />
</shape>
</item>
<item android:bottom="5px">
<shape>
<padding android:bottom="5dp" />
<gradient android:angle="270" android:endColor="#163969" android:startColor="#1c4985" />
<corners android:radius="19dp" />
<padding android:bottom="10dp" android:left="10dp" android:right="5dp" android:top="10dp" />
</shape>
</item>
</layer-list>
</item>
</selector>
Now your button construction is simple.
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="32dp"
android:background="#drawable/button_state_list_animator"
android:text="Save Changes"
android:textColor="#color/button_text_color" />
Here is the screenshot from my code.
You can have the push-down animation using the library as well, as mentioned in an answer here.
Hope that helps!
Use the animation effect (as the code below) on the custom button when clicking on the button.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="1"
android:toXScale="0.8"
android:fromYScale="1"
android:toYScale="0.8"
android:duration="500"
android:pivotX="50%"
android:pivotY="50%" >
</scale>
<alpha
android:fromAlpha="1"
android:toAlpha="0.8"
android:duration="500">
</alpha>
</set>
set Animation on Button Click using.
btn_custom.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R
.anim.animation_btn);
btn_custom.startAnimation(animation);
}
});
try changing alpha values as your need and see the effect.
You can use this library : pushdown-anim-click
How to install:
compile( 'com.github.thekhaeng:pushdown-anim-click:1.1.1' ){
exclude group: 'com.android.support'
}
How to use:
Button button = findViewById( R.id.button );
PushDownAnim.setPushDownAnimTo( button, ... )
.setOnClickListener( new View.OnClickListener(){
#Override
public void onClick( View view ){
Toast.makeText( MainActivity.this, "PUSH DOWN !!", Toast.LENGTH_SHORT ).show();
}
});
For Shadow:
As I saw library files, There are only three java files. He just used class to animate button. You can give shadow in your button by this way. Even though I have created issue You can keep watch on this.
For more functionality, you can visit github link.
Thank you.
Add a layout with the background as the shadow below the button. In the button.setOnTouchListener hide the layout when button is pressed and make it visible when released.
However it will only work if the shadow is below.
I have a button like this
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_centerInParent="true"
android:text="ButtonText"
style="#style/ButtonText"/>
and this style
<style name="ButtonText">
<item name="android:layout_margin">3dp</item>
<item name="android:textSize">20sp</item>
<item name="android:textStyle">bold</item>
<item name="android:shadowColor">#000000</item>
<item name="android:shadowDx">1</item>
<item name="android:shadowDy">1</item>
<item name="android:shadowRadius">2</item>
</style>
Now I want to add radius to button, I have tried <item name="android:radius">6dp</item> but it is not working. What is a solution for this?
In your drawable folder, create a round_button.xml with
<?xml version="1.0" encoding="utf-8"?>
<!-- http://www.dibbus.com/2011/02/gradient-buttons-for-android/ -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<corners
android:radius="2dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>
and then in the xml containing the button, set the background as:
android:background="#drawable/round_button"
I believe to add radius to a button you have to create a custom drawable (see this link, specifically the shape drawable section)
then, with the drawable defined, set the background xml tag of the button equal to your drawable file:
android:background="#drawable/your_file"
I'm using an xml file in drawable to make my buttons in my app 'pretty'.
^ Like that.
It works fine, however I want to add a tick or cross to the buttons (to mark completed or not) - I'm not too sure if it's possible.
Here is my xml for the buttons:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid
android:color="#449def" />
<stroke
android:width="1dp"
android:color="#2f6699" />
<corners
android:radius="3dp" />
<padding
android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#449def"
android:endColor="#2f6699"
android:angle="270" />
<stroke
android:width="1dp"
android:color="#2f6699" />
<corners
android:radius="4dp" />
<padding
android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp" />
</shape>
</item>
</selector>
I'm setting the Background element on the button to use the above like #drawable/bluebuttons
Any help will be really appreciated
If you are using button then you can use Button's property in XML file.
android:drawableRight="#drawable/ANY_DRAWABLE_IMAGE"
In my case it was like this:
<Button android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
...
...
android:drawableRight="#drawable/ic_tick" />
Or in your code, you can put like this:
// PUT ZERO FOR NO DRAWABLE
textView1.setCompoundDrawablesWithIntrinsicBounds(LEFT_DRAWABLE, TOP_DRAWABLE,RIGHT_DRAWABLE, BOTTOM_DRAWABLE);
Hope this will help you.
If you are interested in setting image on button dynamically from Activity then you can use this :
Drawable iconTick= getApplicationContext().getResources().getDrawable(R.drawable.icon_tick);
mBtnTaks1.setCompoundDrawablesWithIntrinsicBounds(iconTick, null, null, null); // left,top,right,bottom
Thanks.