How do I make ImageViews appear behind System Bars? - java

I made this in Android Studio using a FullScreenLayout. I managed to hide the Action bar, but content is still being cutoff where the bar would've been, like the topmost alien.
I'd like the image to be displayed there too, but I haven't been able to find a solution for a FullScreenLayout.
This is the code for the styles.xml file
<resources>
<style name="Widget.Theme.SpaceInvaders.ActionBar.Fullscreen" parent="Widget.AppCompat.ActionBar">
<item name="android:background">#color/black_overlay</item>
</style>
<style name="Widget.Theme.SpaceInvaders.ButtonBar.Fullscreen" parent="">
<item name="android:background">#color/black_overlay</item>
<item name="android:buttonBarStyle">?android:attr/buttonBarStyle</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
The solutions I've seen told me to replace the ActionBar with NoActionBar, but if I do that here, Android Studio tells me that it cannot resolve symbol 'NoActionBar'.
So how do I get rid of both System Bars, and how do I make ImageViews appear where they would've been?

Related

How do I get the style to change based on the resolution of the device?

I've been working on my styles.xml file in order to make a button's text change color based on the resolution the app is loaded at. I did research on Styles and saw that there are qualifiers that can be added to designate the same style based on resolution, like "someStyle" and "someStyle_sw720" for the sw720 resolution. So I defined styles "BodyButtonStyle" and "BodyButtonStyle_sw720" in the app and gave them different values.
Both styles (default and the sw720 style) in styles.xml -
default:
<style name="BodyButtonStyle">
<item name="android:layout_width">280dp</item>
<item name="android:layout_height">50dp</item>
<item name="android:fontFamily">#font/someText</item>
<item name="android:textAllCaps">false</item>
<item name="android:textAlignment">center</item>
<item name="android:textColor">#color/colorWhite</item>
<item name="android:textSize">25sp</item>
<item name="android:background">#drawable/rectangle_shape_button</item>
<item name="android:layout_gravity">center</item>
</style>
sw720:
<style name="BodyButtonStyle_sw720">
<item name="android:layout_width">200dp</item>
<item name="android:layout_height">50dp</item>
<item name="android:fontFamily">#font/someText</item>
<item name="android:textAllCaps">false</item>
<item name="android:textAlignment">center</item>
<item name="android:textColor">#color/colorPurple</item>
<item name="android:textSize">30sp</item>
<item name="android:background">#drawable/rectangle_shape_button</item>
<item name="android:layout_gravity">center</item>
</style>
In the layout I'm using, the style is set to "#style/BodyButtonStyle". I was under the assumption that if I loaded the app on any resolution other than the sw720 one, I'd get white (colorWhite) text, and the sw720 resolution would give it purple (colorPurple) text. I made this assumption because when there are multiple layouts in various resolutions, the app will pick the correct layout to use based on the resolution of the device (i.e a layout called "someLayout" has an sw720 version and an sw800 version, an sw800 device would load the sw800 layout).
Am I missing something here? I've also tried creating additional styles.xml files and loading them with their own "BodyButtonStyle" with different values based on resolution, but the app always seems to load the default regardless of the resolution. Ultimately, my goal is to get a single layout to load different values for elements based on the resolution of the device, and styles seemed to be the solution to that; however, although I seemingly followed the instructions for qualifiers (adding "_sw720" to the style name) it doesn't work, and only loads the default "BodyButtonStyle".
Unless things have changed since I last did this, you need to create separate styles.xml files for each resolution and place them in separate folders. The style name should be the same in both files. One will be placed in the "values" folder and the other one will be placed in "values-sw720dp".

How can I alter colors on Theme.Holo.Dialog?

I got an activity showing as a dialog using
android:theme="#android:style/Theme.Holo.Dialog"
in the manifest file
How can I change the colors of the text and background in the dialog/activity
The simplest way to use this library for custom dialogs. But of course you can build your custom dialog yourself. You can't change the color only (for example the line) without making a custom dialog with your own resources.
Here is the source for the original holo dialog. You can reproduce this, but using the library is faster.
You have to just define your own custom style in values/styles.xml to achieve it.
Step 1- put below code in values/styles.xml file
<style name="UserDialog" parent="android:style/Theme.Dialog">
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:background">#c39797</item>
<item name="android:textColor">#E64C66</item>
</style>
Step-2 And use it AndroidManifest.xml:
android:theme="#style/UserDialog"
Note: you need to create a transparent png drawable if you want to add

Creating bodyless activity

Currently I am trying to make an activity that can be moved on the screen , in other words this activity can float on the screen. I know I am missing something that should be added to achieve this functionality.
What should I do to achieve floating activity which can be moved around anywhere on the screen?
If you're looking to do something similar to the Facebook chat circles (where you have a view on top of other apps) then take a look here: http://www.cloudinfy.com/2013/06/android-chat-head-view-like-in-facebook.html
Basically you need to start a service and add a view to the window manager.
If you're looking to simply create an activity to look like a dialog then have a look here: Android Activity as a dialog
This is very similar to a normal activity but the theme is set to Theme.Dialog
There's a good solution here: http://cases.azoft.com/android-tutorial-floating-activity/
They just add an attribute to the theme of a tablet Activity:
<item name="android:windowIsTranslucent">true</item>
If any problems on KitKat devices, add some lines to the theme:
<item name="android:windowIsFloating">true</item>
<item name="android:windowCloseOnTouchOutside">false</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:backgroundDimEnabled">true</item>

How to change the background colour of the spinner on the aciton bar

I'm working on an android app and have come across an issue, I have managed to get the list items on the action bar to highlight to the color i want but the 'spinner' area around the item is staying the default blue, does anyone know how i can change this color?
I've fixed it!
I used this website which allows you set colors etc. for your action bar and then you just put them in your drawables folder and link it up with the style sheet.
I'm not sure if its the cleanest fix but it works.
http://jgilfelt.github.io/android-actionbarstylegenerator/
Try using android:background within your spinner.
Try this:
(without Sherlok)
<style name="Theme.MyTheme" parent="#style/YourTheme">
<item name="android:selectableItemBackground">#drawable/ab_selector</item>
<item name="android:actionBarWidgetTheme">#style/WidgetStyle</item>
</style>
<style name="WidgetStyle" parent="Widget">
<item name="android:itemBackground">#drawable/ab_menu_selector</item>
</style>

Interaction of Themes, background colors, and Action bar

I am failing to understand the mode of interaction between the appearance of action bar and and thematization. My app is set to use the default theme, which I take to be dark:
<style name="AppBaseTheme" parent="android:Theme">
</style>
Removing the action bar from the app via app-wide style results in black background for the main activity:
<activity
android:name="com.atlarge.motionlog.MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
>
Without the android:theme="#android:style/Theme.NoTitleBar.Fullscreen" line, the activity background is white. If the action bar is removed in code in onCreate() method of the activity, the action bar is also gone, but the background remains white:
ActionBar actionBar = getActionBar();
actionBar.hide();
TL;DR: Summary of behavior:
Action bar present: white background
Action bar removed via code: white background
Action bar removed via XML: black background
Why is that? Can someone explain (or point to a good resource) on the interaction of appearance of action bar via code vs. XML and the background color?
Removing the action bar in the onCreate is just hiding the ActionBar view.
It is not changing the theme.
Setting android:theme="#android:style/Theme.NoTitleBar.Fullscreen" is setting a theme to your activity which comes with any inherited styles in that theme hierarchy.
If you take a look at themes.xml in the android source, you'll see that in the style <style name="Theme"> theres the item <item name="colorBackground">#android:color/background_dark</item>
Then <style name="Theme.NoTitleBar"> which inherits all the styles of Theme sets <item name="android:windowNoTitle">true</item>
Then <style name="Theme.NoTitleBar.Fullscreen"> which inherits from NoTitleBar and Theme sets <item name="android:windowFullscreen">true</item> and <item name="android:windowContentOverlay">#null</item>
which explains why you have a dark background when applying that style.
If you set your theme to Theme.Light.NoTitleBar.Fullscreen you'd achieve the same effect but you'd inherit <item name="colorBackground">#android:color/background_light</item> from <style name="Theme.Light"> which should be a light color.
Alternatively, you can extend any them you want and override any of the styles.
so, for example, you could do something like...
<style name="MyTheme" parent="#android:style/Theme.NoTitleBar.Fullscreen">
<item name="colorBackground">#color/my_light_color</item>
<item name="windowBackground">#drawable/screen_background_selector_light</item>
</style>
Here are some resources that might help you understand themes a bit more:
http://developer.android.com/guide/topics/ui/themes.html
http://brainflush.wordpress.com/2009/03/15/understanding-android-themes-and-styles/
And if you want to create or extend your own themes, its always worth looking at the android source to see what you can extend and override:
http://developer.android.com/guide/topics/ui/themes.html#PlatformStyles
Hope that helps.

Categories