Android Studio's layout editor failing to apply android:windowActionBarOverlay property - android

I am developing a simple app in Android Studio, and I am testing it on a real device (Asus zenfone 5 & Android 4.4.2). In the main activity I have applied this layout:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="madapps.mysecondapp.MainActivity"
android:id="#+id/activity_main" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?android:attr/actionBarSize"
android:orientation="horizontal"
android:background="#drawable/background_deathstar">
<EditText
android:id="#+id/edit_message"
android:text="#string/message" android:layout_weight="1"
android:layout_width="0dp" android:layout_height="wrap_content"
android:hint="#string/edit_message" android:textColor="#FFF" />
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send"
android:onClick="sendMessage" />
</LinearLayout>
with this style.xml applied to the activity
<resources>
<style name="AppTheme" parent="android:Theme.Holo">
<item name="android:windowActionBarOverlay">true</item>
</style>
</resources>
What I want to do is testing a background image on different screen sizes and densities (dpi).
Now, the problem is that while in my physical device the property
android:windowActionBarOverlay
is applied properly, laying out my action bar on top of my background image, this is not working equally within Android Studio's layout editor, meaning that my image begins at the end of the action bar.
ps. I have also noticed that apart from ignoring the windowActionBarOverlay property, my action bar fails to load my custom action buttons. I think these two problems are somewhat related.
Any suggestions?
Thank you very much

Apparently I should have not expected Android Studio's layout editor to reflect what I'm seeing on devices, because it's only using a subset of the real Android layout system.
Actually my action bar is hidden and shown programmatically, and the layout editor is only supposed to serve as a way to drag-and-drop widgets and preview a layout while editing the XML.

Related

Drawable Tinting: Indeterminate ProgressBar [duplicate]

I have the following layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
style="#android:style/Widget.Material.ProgressBar.Large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
I have a Nexus 5 running Android 5.0.1 that doesn't display the ProgressBar, obviously because of the style. When I set the style for example to
style="#android:style/Widget.ProgressBar.Large"
or
style="#android:style/Widget.Holo.ProgressBar.Large"
it is shown. I have an identical Nexus 5 also running Android 5.0.1 which displays all the ProgressBars fine.
Enabling the 'draw layout borders' option in the developers options, it shows that the ProgressBar is included in the layout, it is simply not shown.
This seems very strange, any idea on what could be going on here?
I was having the same issue but was because the developer phone have animations scales to 0 (all 3).
Enable all the animations on the device and maybe you will be able to see the progress bar, so for normal people that will have animations enabled the progress bar will appear fine.
In my case, it looks as if the issue is with build LRX22G:
Nexus 7 using Build LRX22G (android-5.0.2_r1) - progress bar not shown
Nexus 5 using Build LRX22C (android-5.0.1_r1) - progress bar shown
See https://source.android.com/source/build-numbers.html
It's probably also related with https://code.google.com/p/android/issues/detail?id=77865
Not being able to wait for a fix, what I've decided to do is to force the Holo progress bar to be used in my Material theme. This is how it was achieved - it may be of some use to you in the meantime:
<style name="AppBaseTheme" parent="#android:style/Theme.Material.Light.DarkActionBar">
<!-- Build LRX22G (5.0.2 Nexus 7) fails to display progress bar so we'll use Holo instead of Material -->
<!-- http://stackoverflow.com/questions/27567235/certain-progressbar-styles-not-shown-on-nexus-5-android-5-0-1 -->
<item name="android:progressBarStyleSmall">#style/MaterialProgressBarFix.Small</item>
<item name="android:progressBarStyle">#style/MaterialProgressBarFix</item>
<item name="android:progressBarStyleLarge">#style/MaterialProgressBarFix.Large</item>
</style>
<style name="MaterialProgressBarFix.Small" parent="#android:style/Widget.Holo.ProgressBar.Small" />
<style name="MaterialProgressBarFix" parent="#android:style/Widget.Holo.ProgressBar" />
<style name="MaterialProgressBarFix.Large" parent="#android:style/Widget.Holo.ProgressBar.Large" />
By setting the style to the following instead you should be able to debug this issue
style="?android:attr/progressBarStyleLarge"

Lollipop capitalizes Buttons' text in my app

I am expreiencing a strange problem with my application. When I am testing it on a real device (with Android 4.4.4) all my Buttons' text fields look how I wanted (lower case letters). But when I launch my application on an emulator (Android 5.0.1) all Button texts fields are capitalized. What is the reason of such behaviour? Some example Buttons from my app:
Example Button 1:
<Button
android:id="#+id/button5"
android:layout_width="match_parent"
style="?android:attr/borderlessButtonStyle"
android:layout_height="wrap_content"
android:text="#string/finish"
android:textColor="#FFFFFF"
android:textSize="30sp"
/>
Example button 2:
<Button
android:id="#+id/button3"
android:layout_width="0dp"
style="?android:attr/borderlessButtonStyle"
android:layout_height="wrap_content"
android:text="#string/flower"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:drawableLeft="#drawable/flower"
android:layout_weight=".75"
/>
What is the solution to this problem. I want my app to look the same on all sw versions.
Starting with Android 5.0, Buttons automatically have their text capitalized. This is in accordance with the new material design guidelines, which you can find here.
If you want to force your buttons to display the text as it does in previous platform versions, you can set android:textAllCaps="false" in your XML. However, I would recommend against this. Users expect their apps to look material in Android Lollipop, and that means they expect your buttons to display text in all capital letters (even if your app displays the text differently in previous platform versions).
Actually this is possible:
new AlertDialog.Builder(context, R.style.StackedAlertDialogStyle)
StackedAlertDialogStyle:
<style name="StackedAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="buttonBarButtonStyle">#style/StackedButtonBarButtonStyle</item>
</style>
<style name="StackedButtonBarButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:layout_gravity">right</item>
<item name="android:textAllCaps">false</item>
</style>
Now you can see the buttons not in capital.

Certain ProgressBar styles not shown on Nexus 5 Android 5.0.1

I have the following layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
style="#android:style/Widget.Material.ProgressBar.Large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
I have a Nexus 5 running Android 5.0.1 that doesn't display the ProgressBar, obviously because of the style. When I set the style for example to
style="#android:style/Widget.ProgressBar.Large"
or
style="#android:style/Widget.Holo.ProgressBar.Large"
it is shown. I have an identical Nexus 5 also running Android 5.0.1 which displays all the ProgressBars fine.
Enabling the 'draw layout borders' option in the developers options, it shows that the ProgressBar is included in the layout, it is simply not shown.
This seems very strange, any idea on what could be going on here?
I was having the same issue but was because the developer phone have animations scales to 0 (all 3).
Enable all the animations on the device and maybe you will be able to see the progress bar, so for normal people that will have animations enabled the progress bar will appear fine.
In my case, it looks as if the issue is with build LRX22G:
Nexus 7 using Build LRX22G (android-5.0.2_r1) - progress bar not shown
Nexus 5 using Build LRX22C (android-5.0.1_r1) - progress bar shown
See https://source.android.com/source/build-numbers.html
It's probably also related with https://code.google.com/p/android/issues/detail?id=77865
Not being able to wait for a fix, what I've decided to do is to force the Holo progress bar to be used in my Material theme. This is how it was achieved - it may be of some use to you in the meantime:
<style name="AppBaseTheme" parent="#android:style/Theme.Material.Light.DarkActionBar">
<!-- Build LRX22G (5.0.2 Nexus 7) fails to display progress bar so we'll use Holo instead of Material -->
<!-- http://stackoverflow.com/questions/27567235/certain-progressbar-styles-not-shown-on-nexus-5-android-5-0-1 -->
<item name="android:progressBarStyleSmall">#style/MaterialProgressBarFix.Small</item>
<item name="android:progressBarStyle">#style/MaterialProgressBarFix</item>
<item name="android:progressBarStyleLarge">#style/MaterialProgressBarFix.Large</item>
</style>
<style name="MaterialProgressBarFix.Small" parent="#android:style/Widget.Holo.ProgressBar.Small" />
<style name="MaterialProgressBarFix" parent="#android:style/Widget.Holo.ProgressBar" />
<style name="MaterialProgressBarFix.Large" parent="#android:style/Widget.Holo.ProgressBar.Large" />
By setting the style to the following instead you should be able to debug this issue
style="?android:attr/progressBarStyleLarge"

Android layout include no layout

In my app, portrait would have a Button where landscape would NOT have a Button, so I use <include> and did this:
layout/activity_main.xml
...
<include layout="#layout/my_button" />
...
values/layout.xml
...
<item name="my_button" type="layout">#layout/my_button_layout</item>
...
values-land/layout.xml
....
<item name="my_button" type="layout">#layout/empty_layout</item>
layout/my_button_layout.xml
...
<Button...... <!-- my button XML -->
...
layout/empty_layout.xml
<View xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
Now, this works, but I don't quite like the idea of having an useless view whenever the app's in landscape.
I tried to do:
<item name="my_button" type="layout">#null</item>
but this would throw a ResourceNotFound Exception
Is there a way around this?
(Yes I know I can do this programmatically, but then it defeats the purpose of Android's layout system)
You could use two styles. One in an xml file in a portrait folder and the other in another xml file in the landscape folder. These styles could then set android:visibility="gone" and android:visibility="visible" then just set the style onto the button using style="#style/MyButtonStyle"

Theme of Spinner in Action Bar displays correctly in the emulator but wrong on the Phone

I have a problem where the spinner I use display correctly in the emulator but incorrectly on the phone.
This can best be illustrated with this screen shot taken from the phone (notice the light grey background behind the words 'App Priorities 1'):
What it's supposed to look like is like this (taken from the emulator). Here is the text is white and the background black as it should be.
I'm not sure what all the relevant parts of the code is, but I have a folder called values-v14 that contains a single file called styles.xml. The file's contents is:
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar" />
</resources>
This is the spinner XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="fill_horizontal"
android:orientation="vertical" >
<TextView
android:id="#android:id/text1"
style="?android:attr/spinnerItemStyle"
android:singleLine="true"
android:layout_width="150dip"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
</RelativeLayout>
I'm not sure if the manifest is relevant, but I have this in there:
android:minSdkVersion="15"
android:targetSdkVersion="15"
I tried setting the version to 14 but that didn't make any difference.
UPDATE: After adding android:theme="#style/AppTheme" to the Manifest both the emulator and the phone has consistent behavior. The action bar is now dark as it should be. But all the lists have a white background!
Change your AppTheme to Theme.Holo instead of Theme.Holo.Light.DarkActionBar and you'll get your dark background back.
Theme.Holo.Light.DarkActionBar is the same as Theme.Holo.Light (light colored everything) just with, you guessed it, a darker ActionBar.
I am guessing that the phone has the Android 2.x version of Android whereas the emulator is using Android 3+. This means that the emulator has the Holo theme while the phone does not. You have to either create your own theme that copies the Holo theme or live with the fact that it's going to look different on different versions of Android. It's definitely more work to make sure that it still looks good across all versions but it also leads to a more seamless experience.

Categories

Resources