I am setting image as window background:
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:windowBackground">#drawable/bg_window</item>
</style>
It works for tablets and fullscreen windows:
but on the handset it is clipped by status bar:
Is this the way things work? How do I avoid it? Of course, I could set the background for each layout, but I want to know if this the only way to solve the problem.
My solution to this problem (at least for phones) was to create a xml drawable with the statusbar height as the top offset
e.g. drawable/window_background.xml:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:top="25dp">
<bitmap android:src="#drawable/some_background" />
</item>
</layer-list>
This will not work, if the status bar is on the bottom though.
EDIT: edited the answer to use a single xml drawable, as sugested by Aleksejs Mjaliks
Try it in the following way..
<style name="AppTheme" parent="#android:style/Theme.Holo.Light.NoActionBar.Fullscreen">
<item name="android:windowBackground">#drawable/bg_window</item>
</style>
:)
Related
I'm trying to use a 9-patch image as a splash screen, but I get a weird artefact when doing so.
I use the following style on the activity
<style name="AppTheme.Splash" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#drawable/splash_screen</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
This references the following drawable
<?xml version="1.0" encoding="UTF-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="#color/splash_background" />
</item>
<item>
<nine-patch
android:src="#drawable/test_splash"
android:tileMode="disabled"
android:gravity="center" />
</item>
</layer-list>
The 9-patch image has two scalable vertical regions---above and below "Middle". There is no horizontal scaling set.
What this ends up giving me is
Where is that black bar 3/4 of the way down coming from?
I had the same issue. After scrubbing thru all of my splash.9.png files looking for the problem, I retreated and tried one that worked fine in another app. It produced the same artifact.
It seems the issue is with the Theme.AppCompat.Light.NoActionBar. Try this instead:
<style name="splashscreen" parent="android:Theme">
It doesn't look exactly the same around the title bar and such, but it looks like a splash screen.
I don't use Xamarin (I use Titanium), but I had this exact problem when I didn't provide a padding box (the black pixels on the right and bottom). I fixed it by filling the padding lines with black.
I have included a rating bar in android, and now I need to place a text view to immediate right if the rating bar.But I failed to do the same since, there is a lot of unwanted space (rectangular blue box) around the rating bar, which prevents me from placing the textview to its immediate right side. Is there any way to reduce this space around the rating bar , so that both the textview and the rating bar comes in same line and textview is placed next to the rating bar without a gap.Please help me with a good support! Thanks in advance! Here is my xml code for it.
<RatingBar
android:id="#+id/overall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="70dp"
android:numStars="5"
android:rating="0.0"
android:scaleX="0.4"
android:scaleY="0.4"
android:stepSize="0.01" />
You can use android default styles, Like:
style="#android:style/Widget.Holo.Light.RatingBar.Small"
in you xml layout. I am using above and have no space around it.
You can check variants here
I tried to use different suggestion but i was unsuccessful with the Android Rating bar removal of extra padding. All i did downloaded ic icons from https://material.io/icons/ and use star and star bordered icon and programmed them with switch cases.
While using the base style for the RatingBar, set the minHeight to 0dp. The base minHeight in the style itself was preventing the view from scaling down. Setting it to 0 should work as you expect a normal view (we set ours to wrap_content).
Tried to use the base (#android:style/Widget.RatingBar) and small (#android:style/Widget.DeviceDefault.RatingBar.Small and #android:style/Widget.Holo.Light.RatingBar.Small) but both fixed/limited the size of the the RatingBar regardless of what icon is used. Looking at their codes, it was no surprise.
<style name="Widget.RatingBar">
<item name="indeterminateOnly">false</item>
<item name="progressDrawable">#drawable/ratingbar_full</item>
<item name="indeterminateDrawable">#drawable/ratingbar_full</item>
<item name="minHeight">57dip</item>
<item name="maxHeight">57dip</item>
<item name="thumb">#null</item>
<item name="mirrorForRtl">true</item>
</style>
<style name="Widget.Material.RatingBar.Small" parent="Widget.RatingBar.Small">
<item name="progressDrawable">#drawable/ratingbar_small_material</item>
<item name="indeterminateDrawable">#drawable/ratingbar_small_material</item>
<item name="minHeight">16dp</item>
<item name="maxHeight">16dp</item>
</style>
<style name="Widget.Holo.Light.RatingBar.Small" parent="Widget.RatingBar.Small">
<item name="progressDrawable">#drawable/ratingbar_small_holo_light</item>
<item name="indeterminateDrawable">#drawable/ratingbar_small_holo_light</item>
<item name="minHeight">16dip</item>
<item name="maxHeight">16dip</item>
</style>
Setting the scales didn't work right either.
I want to put an indeterminate progress bar inside my ActionBar (using ActionBarSherlock). Everything works, but I want it to be the small progress bar. I use following style:
<style name="IndeterminateProgress" parent="#android:style/Widget.ProgressBar.Small">
<item name="android:progressBarPadding">32dp</item>
<item name="progressBarPadding">32dp</item>
<item name="android:itemPadding">32dp</item>
<item name="itemPadding">32dp</item>
</style>
<style name="Widget.Styled.ActionBar.Tiles" parent="Widget.Sherlock.Light.ActionBar">
<item name="android:indeterminateProgressStyle">#style/IndeterminateProgress</item>
<item name="android:progressBarPadding">32dp</item>
<item name="progressBarPadding">32dp</item>
<item name="android:itemPadding">32dp</item>
<item name="itemPadding">32dp</item>
</style>
The problem is that I cannot set the padding on the progress bar. As you can see above, I've tried every possible combination of itemPadding and progressBarPadding, etc.
The result is always the same:
Any ideas?
I found a working solution how to set indeterminate progress bar with proper size and padding. My solution doesn't use workaround with setActionView(). It is solution for built-in progress bar functionality, supported by native action bar (ActionBarSherlock). Progress bar is enabled/disabled via setProgressBarIndeterminateVisibility(boolean) method. I tested it on Android 2, 3, 4 and ldpi, mdpi, xhdpi.
AndroidManifest.xml:
<application
...
android:theme="#style/Theme.Example">
/res/values/styles.xml:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
...
<style name="Theme.Example" parent="Theme.Sherlock">
<item name="actionBarStyle">#style/Example.ActionBar</item>
<item name="android:actionBarStyle">#style/Example.ActionBar</item>
</style>
<style name="Example.ActionBar" parent="Widget.Sherlock.ActionBar">
<item name="indeterminateProgressStyle">#style/Example.ActionBar.IndeterminateProgressBar</item>
<item name="android:indeterminateProgressStyle">#style/Example.ActionBar.IndeterminateProgressBar</item>
</style>
<style name="Example.ActionBar.IndeterminateProgressBar" parent="#android:style/Widget.ProgressBar.Large.Inverse">
<item name="android:indeterminateDrawable">#drawable/layer_list_ab_indeterminate_progress_bar</item>
<item name="android:minWidth">#dimen/ab_indeterminate_progress_bar_size</item>
<item name="android:maxWidth">#dimen/ab_indeterminate_progress_bar_size</item>
<item name="android:minHeight">#dimen/ab_indeterminate_progress_bar_size</item>
<item name="android:maxHeight">#dimen/ab_indeterminate_progress_bar_size</item>
</style>
</resources>
/res/drawable/layer_list_ab_indeterminate_progress_bar.xml:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<!--
/res/drawable-mdpi/ab_indeterminate_progress_bar asset is taken from
/sdk/platforms/android-18/data/res/mdpi/spinner_white_48.png
and its content (optical square) is resized to ~0.6 (must be even number)
/res/drawable-mdpi-v14/ab_indeterminate_progress_bar asset is taken from
/sdk/platforms/android-18/data/res/mdpi/spinner_48_outer_holo.png
and its content (optical square) is resized to 0.75
-->
<rotate
android:drawable="#drawable/ab_indeterminate_progress_bar"
android:interpolator="#android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="0"
android:toDegrees="360" />
</item>
</layer-list>
/res/values/dimens.xml:
<dimen name="ab_indeterminate_progress_bar_size">48dp</dimen>
Finally I created progress bar assets. I used these two assets from Android SDK:
/sdk/platforms/android-18/data/res/mdpi/spinner_white_48.png for Honeycomb and older
/sdk/platforms/android-18/data/res/mdpi/spinner_48_outer_holo.png for ICS and newer
To get proper size and padding, we need to resize the assets. I resized spinner_white_48.png to ~0.6. For mdpi, it was 28px. It must be even number to be centrally symmetric. I resized only the content, not the whole icon. So icon in mdpi has still 48px, but its content (optical square) is smaller (28px). You can easily resize the content this way: first change "image size" to 28px X 28px, then change "canvas size" back to 48px X 48px. I resized spinner_48_outer_holo.png to 0.75. You can download the assets below.
Why do I use different assets for Honeycomb- and ICS+? Because if I'm using only Holo assets, the animation is little bit snatchy on some devices with Honeycomb-.
Tip: you can add another item with some animation to layer_list_ab_indeterminate_progress_bar.xml. For example standard Holo progress bar uses 2 animations with opposite direction and different degrees range. See progress_medium_holo.xml in SDK.
/res/drawable-mdpi/ab_indeterminate_progress_bar.png:
/res/drawable-mdpi-v14/ab_indeterminate_progress_bar.png (hardly visible on this page):
/res/drawable-hdpi/ab_indeterminate_progress_bar.png:
/res/drawable-hdpi-v14/ab_indeterminate_progress_bar.png (hardly visible on this page):
/res/drawable-xhdpi/ab_indeterminate_progress_bar.png:
/res/drawable-xhdpi-v14/ab_indeterminate_progress_bar.png (hardly visible on this page):
I don't know the exact answer but these settings worked for me..
This is my refresh_spinner.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<ProgressBar android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center"
android:layout_marginRight="12dp"
android:layout_marginLeft="12dp"
style="?indeterminateProgressStyle" />
</FrameLayout>
And this in the corresponding style xml
<style name="Widget.MyTheme.ActionBar" parent="Widget.Sherlock.ActionBar">
<item name="indeterminateProgressStyle">?android:attr/progressBarStyleSmallInverse</item>
</style>
These settings worked for me.
Please let me know if you have any doubts.
Regards
Parvaz Bhaskar
EDIT2 : since I was trying different methods I ended up using ?android:attr/progressBarStyleSmallInverse
as the only property in my style.xml which i later refrenced it from my spinner xml under style as style="?indeterminateProgressStyle"
EDIT:
keep a reference of your menuItem and whenever you want to show a refresh progressbar use setActionView(R.layout.your_layout), and change it to null when the need is over. onCreateOptionsMenu would be a good place to grab the menuItem at start.
I meet this today and find a solution for Android 3/4+
ProgressBar mProgressBarInActionBar = null;
Resources res = Resources.getSystem();
int id = res.getIdentifier("progress_circular", "id", "android");
View internal = findViewById(id);
if(internal != null && internal instanceof ProgressBar){
mProgressBarInActionBar = (ProgressBar)internal;
}
mProgressBarInActionBar.setPadding(0, 0, right, 0);
Set a suitable right :)
I had the same problem and I found an easy answer:
<style name="ActionBarProgressBar.MyStyle" parent="#android:style/Widget.Holo.ProgressBar.Large">
<item name="android:minWidth">56dp</item>
<item name="android:maxWidth">56dp</item>
<item name="android:minHeight">35dp</item>
<item name="android:maxHeight">35dp</item>
</style>
The Width is the standard Actionbar item width. If you change the minHeight and maxHeight, then the image will scale both ways.
And here is the Actionbar styling where you set the appearance of the Indeterminate Progress:
<style name="action_bar_theme" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:indeterminateProgressStyle">#style/ActionBarProgressBar.MyStyle</item>
</style>
And the definition in the Theme you are using (don't forget to use it in your manifest):
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/action_bar_theme</item>
</style>
I'm using the Action Bar for the top of my screen and have buttons there. i'd like an additional sequence of butons at the bottom, but there's too many controls for it to fit in the Action Bar, so I'm creating a Custom View and layout. I'm trying to match the color scheme of hte Action Bar, but I can't figure out what the default Android.R.Color is for the Action Bar.
I've set the custom view's layout as shown. There doesn't seem to be a built in color for light_gray, or anything indicating a menu or action bar default color.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#android:color/darker_gray" />
<stroke android:width="1dip" android:color="#333333"/>
</shape>
you can inspect all the styles by looking at styles.xml in your android SDK platforms folder. e.g.,
<your-sdk-dir>/platforms/android-16/data/res/values/styles.xml
looking at API level 16, this is what i see,
<style name="Widget.ActionBar">
<item name="android:background">#android:drawable/action_bar_background</item>
...
if that resource is not public, your best bet is to set the action bar background and your footer background to something you define. you do this by creating a theme in your styles.xml and overriding the action bar style,
<style name="Theme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/ActionBar</item>
</style>
now create the actual action bar style,
<style name="ActionBar" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/my_background</item>
</style>
now assign this style to your application,
<application
...
android:theme="#style/Theme" >
...
I found myself looking for the colors values inside xml files. I couldn't find it. In the end the most stupid idea was the best:
Print screen of emulator and color picker in gimp. This matched exactly the color I've been looking for.
For me this answer is really stupid. However at the end of a day I've been able to find value very quickly.
I use an ActionBarSherlock library in my app. I also needed to customize the ActionBar, so I added a custom theme with a background parameter set, like this:
<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="background">#drawable/action_bar_bg</item>
<item name="android:background">#drawable/action_bar_bg</item>
</style>
action_bar_bg drawable is simply a bitmap of tiled squares:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true"
android:src="#drawable/bg_img_actionbar"
android:tileMode="repeat" />
What I want to do next is to set a linear gradient for a whole ActionBar, so it will cover this background. And I have no idea if it's possible and how to do that.
Any help would be appreciated.
There is a type of resource for this, Shape Drawable:
http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape