I have been attempting to create an Activity that is opaque which overlaps another activity that is being shown in the background.
This is my XML layout file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".EmergencyActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent" android:background="#color/opaque_back">
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/button"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintBottom_toBottomOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</RelativeLayout>
Manifest file:
<activity
android:name=".EmergencyActivity"
android:theme="#style/Theme.Transparent">
Style:
<style name="Theme.Transparent" parent="AppTheme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
Images of the screens:
https://imgur.com/cqfBlNM - first activity screen
https://imgur.com/NUjTAdj - screen of the activity that isn't being fully displayed
I solved it by changing from appCompactActivity to Activity in order to use another style which isn't supported by the AppCompactActivity.
I changed the manifest to:
<activity
android:name=".EmergencyActivity"
android:launchMode="singleInstance"
android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen">
Your question is not clear enough but if you want to make an activity display full screen try this inside the activity class :
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Related
I am trying to create an activity that will match the parent height. When I am testing the application on Pixel XL the application is fine, but when install on Xiaomi Redmi Note 9 Pro I have one part of the screen that it's not covered. This is the part above the camera, and it might be that my question is not only for this phone but I guess for all the others with the same design.
This is how it looks on pixel and it's ok:
And this is how it looks on Xiaomi Redmi Note 9 Pro:
This is my activity code:
<?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:background="#color/main_screen_background"
tools:context=".activty.WelcomeActivity">
<include layout="#layout/toolbar" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/main_menu_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar"
android:layout_marginTop="20dp"
android:layout_marginBottom="60dp" />
</RelativeLayout>
And this is my Toolbar if needed:
<androidx.appcompat.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/main_screen_background"
android:theme="#style/AppFullScreenTheme"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<RelativeLayout
android:id="#+id/test_menu_language_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="30dp">
<ImageView
android:id="#+id/about_dropdown_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_ikonki_potrosuvaci_02" />
<TextView
android:id="#+id/language_dropdown_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:text="MK"
android:textColor="#color/white"
android:textSize="20dp" />
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
What I want to achieve is to have covered also that black part and have the color from the activity, probably an easy thing but I am little rusty with android. I checked the other applications and they are covering that part.
So actually there are only two lines of code needed to be added in your v27/styles.xml:
<item name="android:windowLayoutInDisplayCutoutMode">
shortEdges <!-- default, shortEdges, never -->
</item>
<item name="android:windowTranslucentStatus">true</item>
The first will cover that area and the second will set the color of the activity to that area. This is how my styles.xml looks like:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppFullScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowLayoutInDisplayCutoutMode">
shortEdges <!-- default, shortEdges, never -->
</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item>
<item name="android:textAppearanceLargePopupMenu">#style/myPopupMenuTextAppearanceLarge
</item>
<item name="android:textAppearanceSmallPopupMenu">#style/myPopupMenuTextAppearanceSmall
</item>
</style>
</resources>
Finally I have applied this style to every activity that I have.
How do I get rid of the white box at the top of the android view? I cannot see anywhere in my code where I called something that created the toolbar, nor did I code it myself. It also exists above the view, not in it. I'm guessing there is some setting in the design view of the xml file that can toggle it? Thanks in advance!
** I should also include that it is only on this activity, and my other activities do not have this white bar at the top. Furthermore, the actionbar is the thin blue bar above the white car, so any code that involves manipulating the actionbar will not change the white bar's status. **
EDIT: XML Code is below
<?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:background="#drawable/bucket"
android:theme="#+id/BucketTheme2"
android:backgroundTint="#70FFFFFF"
android:backgroundTintMode="src_over">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow>
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:paddingBottom="5dp"
android:paddingTop="100dp"
android:text="Find a place to go around you!"
android:textColor="#ff000000"
android:textSize="18dp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:onClick="randomButtonPressed"
android:text="RANDOMIZE"
android:textSize="20dp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/bucketBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:onClick="bucketButtonPressed"
android:text="Bucket List"
android:textSize="20dp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/searchLocationBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:onClick="searchButtonPressed"
android:text="Search by Location"
android:textSize="20dp" />
</TableRow>
</TableLayout>
</RelativeLayout>
EDIT 2: style.xml code for BucketTheme2 is below (I did not post it initially because it only sets colors):
<style name="BucketTheme2" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Set theme for application or activity in Manifest.xml to remove action bar:
android:theme="#android:style/Theme.Holo.Light.NoActionBar"
Or add the following code in Activity in the onCreate method and import android.support.v7.app.ActionBar:
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
Add the following theme to the style.xml
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Then set this theme to the activity in manifest:
<activity
android:name=".MainActivity"
android:theme="#style/AppTheme.NoActionBar"/>
UPDATE: You can also set the theme as below:
<style name="BucketTheme2" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Hope this helps.
Change your activity theme in manifest to Theme.AppCompat.Light.NoActionBar and you should be sorted
Add NoActionBar style in style.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowContentOverlay">#null</item>
</style>
And add this theme to your activity from manifest,
<activity android:name=".YourActivity"
android:theme="#style/AppTheme"
>
</activity>
try
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
it should be before setContentView
Just try this in your style
<style name="BucketTheme2" parent="android:Theme.Holo.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
I ran into this same issue when using a template project that Android studio already set up. I noticed that in the activity_main.xml file there was unnecessary padding at the top once I changed to a theme of *.NoActionBar. If you remove android:paddingTop="?attr/actionBarSize" it should go away.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize"></androidx.constraintlayout.widget.ConstraintLayout>
I have layout with centered Image View.
<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/WHITE">
<ImageView
android:id="#+id/powered_by"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/powered_by" />
<ImageView
android:id="#+id/splash_logo"
android:src="#drawable/logo"
app:layout_widthPercent="70%"
app:layout_heightPercent="70%"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
android:visibility="invisible" />
</android.support.percent.PercentRelativeLayout>
Here is theme setting for my activity
<style name="SplashTheme" parent="android:Theme.Holo.Light">
<item name="android:windowBackground">#drawable/splash</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
When i change parent theme to android:Theme.DeviceDefault.Light, ImageView appears a little bit higher, not in center of the screen. It seems like parent view for my device now starts not from the bottom of the screen, but from the bottom toolbar (i use Nexus 5X with on-screen buttons).
I want to use device default theme for a modern dialog appearance, but i also need to have this image view exactly in center on all devices.
How to do it?
It seems like android:Theme.DeviceDefault.Light is not setting android:windowFullScreen. So you will need to create your own theme with the parent android:Theme.DeviceDefault.Light and change the values for the items you want to change
<style name="TestTheme" parent="android:Theme.DeviceDefault.Light">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
I created an Activity (which has and YoutubePlayerView and other image) with transparent background using
following code:
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:backgroundDimAmount">0.9</item>
After compiling, background is Dimmed correctly with DimAmount = 0.9. BUT, my VideoView also dimmed
with same dimAmount.
Full xml for my Activity:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#33000000"
android:orientation="vertical" >
<com.google.android.youtube.player.YouTubePlayerView
android:id="#+id/youtube_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/other_views"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:scaleType="fitStart"
android:src="#drawable/ads" />
</LinearLayout>
How Can I fix it.
Thanks!
Put this theme in the activity tag in your project's manifest.
android:theme="#android:style/Theme.Translucent.NoTitleBar"
it will make your activity completely transparent.
Then set the background of the root layout oht that activity in black with some alpha according to your requirement using this.
android:background="#33000000"
Change 33 as per your requirement.
It will dim the background things without effecting other views.
Hop this works for you.
I want to use an Activity which has normal views and controls.
I made the background of it as an image and I can't make this image transparent
Here's my code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/honey"
>
</RelativeLayout>
I want just the image to be transparent
try this for transparent background:
in the file AndroidManifest.xml
<activity android:name="YourActivity" android:theme="#style/TransparentStyle"></activity>
in the file /res/values/style.xml
<resources>
<style name="TransparentStyle">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Translucent</item>
<item name ="android:windowBackground">#00000000</item>
<item name="android:windowNoTitle">true</item>
<item name="android:colorForeground">#ffffff</item>
</style>
</resources>
and try this for transparent image:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/yourImage"
android:alpha=".75"/>