Translucent/transparent activity in Android Wear Lollipop - android

I had translucent activity backgrounds working on Android Wear 4.4W, by not specifying a theme, and setting the background in the activity layout to #BB000000.
Now I have Android Wear 5.0.1, the background is not translucent, and weird effects occur with elements of the foreground appearing in random places in the background, and jumping around - completely messed up.
I've tried to use a custom theme as follows:
<style name="Theme.Transparent" parent="android:Theme.DeviceDefault">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
</style>
I also tried using
android:theme="#android:style/Theme.Translucent"
Both with no luck - the same weird opaque effects.
My activity layout is as follows:
<android.support.wearable.view.BoxInsetLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#BB000000"
android:layout_height="match_parent"
android:layout_width="match_parent">
<FrameLayout
android:id="#+id/frame_layout"
android:layout_height="match_parent"
android:layout_width="match_parent"
app:layout_box="left|bottom|right">
<android.support.wearable.view.WearableListView
android:id="#+id/wearable_list"
android:layout_height="match_parent"
android:layout_width="match_parent">
</android.support.wearable.view.WearableListView>
</FrameLayout>
</android.support.wearable.view.BoxInsetLayout>
Any ideas anyone?

Just tested in Android Wear 5.1.1
android:theme="#android:style/Theme.Translucent"
now gives a translucent background.

Related

ThemeOverlay not showing changes in the preview/design view in Android Studio after update

I just recently updated my Android Studio and ever since doing that the ThemeOverlay property is not showing on my buttons in the preview/design editor which it did prior to the update. However when I run the App on the Device the ThemeOverlay works. Below is some test code for the button. I have set the background attribute of the Button to Blue and the text of the button to Test Me
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test Me"
android:background="#0000FF"
android:layout_marginTop="20dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark"/>
</LinearLayout>
The theme attribute is set to TheOverLay.AppCompat.Dark so that the text on the button is light but it's not showing in the design editor/preview in Android Studio. The text still shows as dark/Black. When I run this on a connected device it works fine.
Is this because of something that has changed with the current update?
You can set this inside your base theme:
<item name="android:colorButtonNormal">#color/some_color</item> which is global basically, all the buttons will have the color you defined inside your theme file.
On the other hand, I believe you cannot get the button theme from ThemeOverlay. Instead, create a new style and set the parent to Button.
<style name="CustomButton" parent="Widget.AppCompat.Button.Colored">
<item name="colorButtonNormal">#color/Red</item>
<item name="android:colorButtonNormal">#color/Red</item>
<item name="android:textColor">#color/White</item>
</style>
And you can apply the style as:
android:theme="#style/CustomButton"

Android find default background color

I have an app with a simple recyclerview.
The layout is declared as follow
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/contentView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/some_id" />
</RelativeLayout>
I notice that on different devices, the recyclerView actually had a different background. In newer devices, the background is just white. On older devices, the background is light gray.
In android studio, the background color is blank in the design view.
So my question is, where does this gray color come from? How can I change it universally to white?
I can obviously just add background:white to this particular view. But is there a way to overwrite the system default?
Android default background color
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:colorBackground">
</RelativeLayout
use
android:background="?android:colorBackground"
What you are seeing is actually the background of the activity, not the recyclerview, which is transparent by default. The color did change a view time per Android version.
You can override this in your app theme.
First define the color in values/colors.xml
<resources>
<color name="background">#FF0000 </color>
</resources>
Create a themes.xml file in res/values that references that color:
<resources>
<style name="MyTheme" parent="#android:style/Theme.Light">
<item name="android:windowBackground">#color/background</item>
</style>
</resources>
and then in your AndroidManifest.xml specify this as
the theme for your activities to use.
<activity
android:name=".MyActivity"
android:theme="#style/MyTheme" />
see https://stackoverflow.com/a/10157077/4623782
it's because of theme. specify your theme in res/values/style.xml. or set manually in view definition.
<android.support.v7.widget.RecyclerView
android:id="#+id/contentView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/some_id"
android:background="#android:color/white"
/>
it will give you white background on all device
The color of the background which is set by default in any android studio project is #fafafa

Theme.AppCompat.Dialog theme creates empty (dead) space

In my application, I am using an Activity with the theme "Theme.AppCompat.Dialog" to display it as a dialog. That works out well, however, the dialog fills the entire screen height, leaving a lot of space empty. To illustrate my issue, here is a picture of opening the dialog (on an unusually high resolution to demonstrate the issue better):
The higher the resolution, the greater this space.
Here is a code snippet:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:tools="http://schemas.android.com/tools">
<!--This is the yellow box-->
<LinearLayout
android:id="#+id/dialog_button_bar"
android:layout_alignParentBottom="true"
style="?android:buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content">
[Buttons...]
</LinearLayout>
<!--This is the red box-->
<ScrollView
android:layout_above="#id/dialog_button_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
[LinearLayout containing rows...]
</ScrollView>
If I remove the android:layout_alignParentBottom="true" and the android:layout_above="#id/dialog_button_bar" attributes, the whole layout jumps to the top and now the empty space is below my layout.
What am I doing wrong? :(
It seems like this is some kind of intended behavior. The standard Android app installation dialog seems to behave the same way (leaving a lot of blank space between the permission part and the buttons) so I guess I'll keep it this way...
Create new Style in styles.xml
<style name="MyCustomDialog" parent="Base.Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
Now in AndroidManifest.xml, add android:theme="#style/MyCustomDialog" to your Dialog activity.

Style displayed in emulator but not on my device

I've following style.xml in res/values/ folder:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:colorBackground">#000000</item>
</style>
and the following layout for my main activity, where I've used style="#style/AppTheme":
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
style="#style/AppTheme" // here I've used It.
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.kaushal28.wakeupplease.MainActivity">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:id="#+id/startAlarm" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/stop"
android:text="Stop"/>
</LinearLayout>
</RelativeLayout>
I've device with Android 4.2.2 Jelly Bean and emulator has latest Marsh mellow. I think the problem is because of this difference only. I've minimum SDK version 15 for this project.
I tried to change targetSDKVersion to 15 in Build.Gradle. But it couldn't solve my problem.
What should be displayed:
What is displaying:
I'm expecting Black color in background.
Try to use android:windowBackground instead of android:colorBackground
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowBackground">#android:color/black</item>
</style>
Why?
By your screen, I saw that you are trying to set window background. So, the best attribute to that is android:windowBackground.
Your AppTheme is not overriding android:windowBackground.. it was only overriding android:colorBackground.
Since you are not overriding android:windowBackground, Android will use the color defined in your parent theme (Theme.AppCompat.Light.DarkActionBar).
So, Android was using:
<item name="colorBackgroundFloating">#color/background_floating_material_light</item>
and
<color name="background_material_light">#color/material_grey_50</color>
<color name="material_grey_50">#fffafafa</color>
It is almost a white color.
Device vs Studio
I'll be honest.. I'm not totally sure why your device was ignoring android:colorBackground while emulator was using it...
Probably, is the API version or probably, it is just a normal behavior since your device shows the theme applied to an Activity and inside a whole context.. Your device will be always a little bit different from Android Studio Layout Preview tool.
For any instance, I recommend to use android:windowBackground if you want to sent whole window background...
android:colorBackground can affects not only the background of the main window but also of all the components e.g. dialogs unless you override it in the component layout. (this part was retrieved from here)

Android windowActionModeOverlay not working in landscape

I am working on an android app with the toolbar using the support library. I have set
<item name="windowActionModeOverlay">true</item>
in my app style and now my Action Mode overlays properly over the toolbar in portrait mode.
However, when I switch to landscape mode, a little sliver of the tool bar is still seen below my action mode.
You can see the image of what I'm talking about here
My toolbar code is pasted below. I include this in all of my activities. I have tried setting the elevation to 0dp but the problem still persists.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/primary"
android:theme="#style/ThemeOverlay.AppCompat.Dark"
app:popupTheme="#style/AppTheme.Menu"
android:elevation="4dp">
</android.support.v7.widget.Toolbar>
AppTheme.Menu looks like the following:
<style name="AppTheme.Menu" parent="ThemeOverlay.AppCompat.Light">
<item name="android:colorBackground">#android:color/white</item>
<item name="android:textColor">#color/primary_dark</item>
</style>

Categories

Resources