I am using an XML drawable as splash screen which is a layer-list element. Inside it, I am using an animation.xml file, which contains a loading animation.
While showing the splash screen, I can see the loading animation drawable, but without any animation. I am probably doing something wrong.
Can anyone please point me out the correct way?
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/purple_700" />
<item
android:drawable="#drawable/ic_launcher_foreground"
android:gravity="center" />
<item
android:width="300dp"
android:height="300dp"
android:drawable="#drawable/loading_animation"
android:gravity="bottom" />
</layer-list>
Thanks for your help!
Try to place the last item with this:
<item
android:width="300dp"
android:height="300dp">
<animated-rotate
android:drawable="#drawable/loading_image"
android:pivotX="50%"
android:pivotY="50%" />
</item>
I am trying to get something like this:
I need to continuously change the color of each arc sequentially to give a 'wave' like feel to it.
I don't know whether I should use Canvas to draw the entire animation or use drawable resource files.
Can anyone please suggest which would be better and why? Also , if you can link a similar looking animation which can be used as reference for this then that would be great too! Thanks
Define the drawable file. The root node element can be animation-list
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item
android:drawable="#drawable/ic_volume_s1"
android:duration="400" />
<item
android:drawable="#drawable/ic_volume_s2"
android:duration="400" />
<item
android:drawable="#drawable/ic_volume_s3"
android:duration="400" />
<item
android:drawable="#drawable/ic_volume_s4"
android:duration="400" />
<item
android:drawable="#drawable/ic_volume_s5"
android:duration="400" />
</animation-list>
Is it possible to define state list for compound drawables in Android?
This is my button in layout xml:
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/btn_top"
android:text="#string/button_text" />
This is my drawable xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_enabled="true" android:drawable="#drawable/btn_top_enabled" />
<item android:drawable="#drawable/btn_top_disabled" />
</selector>
This works for background, but its not working for drawableTop. The first state is always displayed. Is this even possible in Android, and if so am I missing something?
look ad TextView.java source code and you will see that yes, you can use StateListDrawable as a compound Drawable that displays according to TextView state
Try:
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_enabled="true" android:drawable="#drawable/btn_top_enabled" />
<item android:state_activated="true" android:drawable="#drawable/btn_top_enabled" />
<item android:drawable="#drawable/btn_top_disabled" />
</selector>
And
button.setActivated(true);
I have some kind ListView. All items in it are in rectangle shape, but the top one has round corners as shown in this photo. To create it I've cut the top stripe with corners and saved it as item_bg_white_top image and a stripe with 1px height saved as item_bg_white_line image. And this is how I've constructed it.
I want to make flash effect when clicking on ltest layout just like clicking on ListView item.
How I can do this?
I've tried the code below on ltest but it it didn't helped. When I tried this code on ltest_inner it just changed its background to black.
final LinearLayout ll = (LinearLayout)findViewById(R.id.ltest);
ll.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ll.setBackgroundResource(android.R.drawable.list_selector_background);
}
});
item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/ltest"
android:layout_width="300dp"
android:layout_height="33dp"
android:orientation="vertical">
<LinearLayout
android:id="#+id/ltest_inner"
android:layout_width="300dp"
android:layout_height="8dp"
android:background="#drawable/item_bg_white_top" />
<LinearLayout
android:layout_width="300dp"
android:layout_height="25dp"
android:background="#drawable/item_bg_white_line_repeat" >
</LinearLayout>
</LinearLayout>
item_bg_white_line_repeat.xml
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/item_bg_white_line"
android:tileMode="repeat" />
What you want to do is set up a selector and use it as the drawable for the background.
Create an xml file in your drawable folder and add a selector to it:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:state_pressed="true" android:drawable="#drawable/disabled_pressed_image" />
<item android:state_enabled="false" android:state_focused="true" android:drawable="#drawable/enabled_focused_image" />
<item android:state_enabled="false" android:drawable="#drawable/enabled_image" />
<item android:state_focused="true" android:drawable="#drawable/focused_image" />
<item android:state_pressed="true" android:drawable="#drawable/pressed_image" />
<item android:drawable="#drawable/default_image" />
</selector>
The drawables above reference images also in your drawable folder. You don't have to implement all the states. Those are just some possible combinations.
Then attach this as the background to your Linear Layout:
<LinearLayout
android:id="#+id/ltest"
android:layout_width="300dp"
android:layout_height="33dp"
android:background="#drawable/selector_file_name"
android:orientation="vertical">
where selector file name is simply the name you gave to the selector xml file I mentioned above.
Also consider removing the inner LinearLayouts. You can do what you are trying to do with a 9-patch, then you'll only have the one LinearLayout (which you could just change to an ImageView if it is not going to host other Views).
I would like to know how I can change indeterminate ProgressBar color from basis white/grey color to black ? When I change the indeterminateDrawable, I get a static image instead of a moving animated progressBar. Is there any way to do it simply in XML?
progressBar.getIndeterminateDrawable().setColorFilter(
getResources().getColor(Your_Color),
android.graphics.PorterDuff.Mode.SRC_IN);
and replace Your_Color with the desired color like: R.color.your_color_code
To get a ProgressBar in the default theme that is to be used on white/light back ground, use one of the inverse styles:
<ProgressBar style="#android:style/Widget.ProgressBar.Inverse"/>
<ProgressBar style="#android:style/Widget.ProgressBar.Large.Inverse"/>
<ProgressBar style="#android:style/Widget.ProgressBar.Small.Inverse"/>
This will usually give you a black on transparent ProgressBar, but some OS installs use custom assets. If you're looking for a specific color, you'll have to roll your own drawables by following the instructions provided by CommonsWare.
I see other answers are quite old, in order to change the indeterminate ProgressBar color you have just to set android:indeterminateTint and android:indeterminateTintMode attributes in your ProgressBar item directly in XML:
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateTint="#color/colorPrimary"
android:indeterminateTintMode="src_in"
android:indeterminate="true" />
android:indeterminateTint - Tint to apply to the indeterminate progress indicator.
Must be a color value, in the form of "#rgb", "#argb", "#rrggbb", "#aarrggbb", or a reference to a resource #color/colorPrimary.
android:indeterminateTintMode - Blending mode used to apply the progress indicator tint.
Must be one of the following constant values:
add, multiply, screen, src_atop, src_in or src_over
Getter and Setter methods for these attributes are:
getIndeterminateTintList()
getIndeterminateTintMode()
setIndeterminateTintList(ColorStateList tint)
setIndeterminateTintMode(PorterDuff.Mode tintMode)
All of them were added in API level 21
I make sample project and post in in my blog. Please, look at. http://www.hrupin.com/2011/09/21/how-to-make-custom-indeterminate-progressbar-in-android-or-how-to-change-progressbar-style-or-color
Hope, it help you
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background" android:drawable="#drawable/bg" />
<item android:id="#android:id/secondaryProgress" android:drawable="#drawable/secondary" />
<item android:id="#android:id/progress" android:drawable="#drawable/progress" />
</layer-list>
For API less than 23 use
progressBar.getIndeterminateDrawable().setColorFilter(
getResources().getColor(Your_Color),
android.graphics.PorterDuff.Mode.SRC_IN);
else use
progressBar.getIndeterminateDrawable().setColorFilter(
ContextCompat.getColor(context, Your_Color),
android.graphics.PorterDuff.Mode.SRC_IN);
Override android:colorControlActivated in your AppTheme which should be in your styles.xml:
<style name="AppTheme" parent="...">
...
<item name="android:colorControlActivated">#color/beautiful_color</item>
...
</style>
Works on API 21+
With the Material Component Library you can use the CircularProgressIndicator with these attributes:
indicatorColor
trackColor
Something like:
<com.google.android.material.progressindicator.CircularProgressIndicator
android:indeterminate="true"
app:trackColor="#color/red600Light"
app:indicatorColor="#color/red600Dark"
app:indicatorSize="50dp"
.../>
You can also use a Multi-color indeterminate indicator.
<com.google.android.material.progressindicator.CircularProgressIndicator
android:indeterminate="true"
app:trackColor="#color/red600Light"
app:indicatorColor="#array/progress_colors"
app:indeterminateAnimationType="contiguous"/>
with array/progress_colors:
<integer-array name="progress_colors">
<item>#color/...</item>
<item>#color/...</item>
<item>#color/...</item>
</integer-array>
actually all u need to do (for both cirle and bar) is create an xml file in drawable as shown below......
progress_spinner_001 points to whatever image u want to animate and duration ... how long u want to display each frame for.......
and set ur android:indeterminateDrawable= filename_in_drawable....
<?xml version="1.0" encoding="utf-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="#drawable/progress_spinner_001" android:duration="300" />
<item android:drawable="#drawable/progress_spinner_002" android:duration="300" />
<item android:drawable="#drawable/progress_spinner_003" android:duration="300" />
<item android:drawable="#drawable/progress_spinner_004" android:duration="300" />
<item android:drawable="#drawable/progress_spinner_005" android:duration="300" />
<item android:drawable="#drawable/progress_spinner_006" android:duration="300" />
<item android:drawable="#drawable/progress_spinner_007" android:duration="300" />
<item android:drawable="#drawable/progress_spinner_008" android:duration="300" />
</animation-list>
ps u may need to resize the progressbar to show as desired