How to make the statusbar black (default) in android? - android

One of my activities has suddenly changed its color in the statusbar. By default it's black, but now it's transparent, why?
I've marked around the bar with a circle. By default this is black
My XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:id="#+id/do2get"
android:src="#drawable/loading"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="30dp" />
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:indeterminateTint="#00796b"
android:id="#+id/progressBar"
android:layout_below="#+id/do2get"
android:layout_centerHorizontal="true"
android:indeterminateTintMode="src_in"/>
</RelativeLayout>

I think its all about your actitiy`s theme.
First of all check this links:
How to change the status bar color in android
How to change the background color of android status bar
Maybe your base theme has attribute "android:windowTranslucentStatus" = true or "colorPrimaryDark = #android:color/transparent" etc. So you need to create new one style like:
<style name="YourActivityTheme" parent="BaseAppTheme">
<item name="android:windowTranslucentStatus">false</item>
<item name="android:statusBarColor">#android:color/black</item>
</style>
and then set this style to current activity theme in AndroidManifest:
<aplication
....... >
.......
<activity
android:name=".chapters.home.YourNiceActivity"
android:theme="#style/YourActivityTheme">
<intent-filter>
...
</intent-filter>
</activity>
.....
</application>

Related

How do I add back the transparent background around my dialog activity with a custom theme

I have an activity and I've set it's theme in the manifest to a custom dialog theme.
But now the transparency around the dialog box is gone. Everything is black.
Here's what it looks like with my custom theme:
I want it to look like this:
But with a custom background and text color, like in the first picture.
Here's the part of the manifest with the activity's theme set to my custom theme, as in the first picture:
<activity
android:name=".activity.LockScreenActivity"
android:exported="true"
android:label="#string/aplicacao_bloqueada_title"
android:theme="#style/dialog_theme"/>
Here's the part of the manifest with the activity's theme set to android's dialog theme, as in the second picture:
<activity
android:name=".activity.LockScreenActivity"
android:exported="true"
android:label="#string/aplicacao_bloqueada_title"
android:theme="#style/Theme.AppCompat.DayNight.Dialog"/>
Here's my xml with my custom theme:
<style name="dialog_theme" parent="Theme.AppCompat.DayNight.Dialog">
<item name="android:textColor">#color/white</item>
<item name="android:windowBackground">#color/dark_gray</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:backgroundDimAmount">50</item>
</style>
Here's my activity class:
public class LockScreenActivity extends AppCompatActivity {
// Notification activity that is called after too many failed login attempts
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lock_screen);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
finishAndRemoveTask();
System.exit(0);
}
}, 5000);
}
}
Layout for my activity:
<androidx.constraintlayout.widget.ConstraintLayout 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="wrap_content"
tools:context=".activity.LockScreenActivity">
<TextView
android:id="#+id/textView2"
android:layout_width="214dp"
android:layout_height="136dp"
android:gravity="center_vertical"
android:padding="20dp"
android:text="#string/aplicacao_bloqueada_text"
android:textAlignment="viewStart"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
What's the best way to do this?
Edit: As nima sugested, I tried adding the following line to the onCreat method of my dialog themed class:
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
But it turned everything transparent, including the pop up window.
See picture:
How do I solve this?
Edit Your Code Like Bellow:
1-In style
<style name="dialog_theme" parent="Theme.AppCompat.DayNight.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
</style>
2-In Manifest
<activity
android:name=".activity.LockScreenActivity"
android:exported="true"
android:theme="#style/dialog_theme"
android:label=""
/>
3-activity_lock_screen
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/cardview_dark_background"
android:gravity="center"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="170dp">
<TextView
android:id="#+id/textView2"
android:layout_width="214dp"
android:layout_height="0dp"
android:layout_weight=".2"
android:gravity="center"
android:padding="20dp"
android:text="Application Blocked !"
android:textColor="#color/white"
android:textSize="16sp"
/>
<TextView
android:id="#+id/textView3"
android:layout_width="214dp"
android:layout_height="0dp"
android:textColor="#color/white"
android:layout_weight=".4"
android:gravity="center_horizontal"
android:padding="20dp"
android:text="#string/aplicacao_bloqueada_text"
android:textSize="16sp" />
</LinearLayout>
As #nima pointed out you can use getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); to make the background transparent.
This will introduce a couple of issues:
Transparency of everything
Fix this by setting a white background to the ConstraintLayout root layout.
Transparent activity title
Fix this by removing the title from the manifest and set it to an empty one in activity with setTitle(""); and add another TextView to represent the title in the layout:
Remove the title (android:label) from the activity in the manifest:
Also you should android:exported="true" as it seems that this activity should be exported to other apps:
<activity
android:name=".activity.LockScreenActivity"
android:theme="#style/Theme.AppCompat.DayNight.Dialog"/>
Set the title & background:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lock_screen);
// ...........
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
setTitle("");
}
Layout:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:paddingHorizontal="16dp"
android:paddingTop="16dp"
tools:context=".LockScreenActivity">
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Application Blocked"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="#id/textView2"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView2"
android:layout_width="214dp"
android:layout_height="136dp"
android:gravity="center_vertical"
android:padding="20dp"
android:text="#string/aplicacao_bloqueada_text"
android:textAlignment="viewStart"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView1" />
</androidx.constraintlayout.widget.ConstraintLayout>
UPDATE:
When I use my custom theme, as opposed to Theme.AppCompat.DayNight.Dialog, I still get the black screen
This is because the android:backgroundDimAmount is set to 50 in your custom theme; the valid range for this attribute is 0 through 1; any value greater than that will be considered 1...
0 means there is no dimming (completely transparent, and 1 meaning 100% opaque/black.
So to fix this issue, I guess you mean by 50 as the half way, so you'd set it to 0.5 instead:
<style name="dialog_theme" parent="Theme.AppCompat.DayNight.Dialog">
<item name="android:textColor">#color/white</item>
<item name="android:windowBackground">#color/dark_gray</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:backgroundDimAmount">0.5</item>
</style>
Your backgroundDimAmount is too high try some smaller number like 0.5
So your dialog_theme would look something like this.
<style name="dialog_theme" parent="Theme.AppCompat.DayNight.Dialog">
<item name="android:textColor">#color/white</item>
<item name="android:windowBackground">#color/dark_gray</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:backgroundDimAmount">0.5</item>
</style>

Android: How to get rid of the header bar in App?

For some reasons when I launch the app in the splash activity and in the row activity, see images, there is a header bar with the name of the app "Baby Read".
I don't want the header there, how do I get rid of it?
Splash Activity
Row Activity
[![enter image description here][2]][2]
This is the splash 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"
android:background="#drawable/babyreadappsplash"
>
</LinearLayout>
And this is the row layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="#+id/icon"
android:layout_width="90px"
android:layout_height="90px"
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
android:layout_marginBottom="10px"
android:layout_marginTop="10px"
android:src="#drawable/ic_launcher" >
</ImageView>
<TextView
android:id="#+id/label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#+id/label"
>
</TextView>
This is res/values/styles after adding the code suggested
[![enter image description here][3]][3]
And this is the manifest after adding the code suggested
Create a style for your splash Activity like this
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
</style>
after that set this style for your splash Activity in Manifest
<activity
android:name="activity name"
android:theme="#style/AppTheme.NoActionBar"
/>
Update
make your style like this
<style name="splashStyle" parent="Theme.AppCompat.Light.NoActionBar">
//add other attributes
</style>
if not work for you change the parent of your AppTheme to Theme.AppCompat.Light.ActionBar
You can use this in onCreate:
getSupportActionBar().hide();
No need to create anew theme (At least for this purpose)
Modify you app theme (Picture one)change parent="android:Theme.Holo.Light.DarkActionBar" for parent="android:Theme.Holo.NoActionBar"
On you manifest, in the application section (picture 2)add
android:theme="#style/AppTheme"
If by any change you are supporting APIs below 13 you can add
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
to your app theme rather than changing the parent.
As a side note I would advise moving from Holo themes to Appcompat or even Material, but that´s out of the scope of this question

Change position of App title in Action Bar

I would like to change the position of the title of my app to be on the right of my icon in my action bar (as it is in the gmail android app). Currently, the app looks like:
I would like the vertical bars to appear to the left of the app title. My current styles.xml is:
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/ActionBarTheme</item>
</style>
<style name="ActionBarTheme" parent="android:Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/primary</item>
<item name="android:logo">#color/transparent</item>
</style>
</resources>
and my menu xml is:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#+id/action_menu"
android:icon="#drawable/ic_menu_white_36dp"
android:title="Menu"
android:showAsAction="always"
/>
</menu>
Where is your ic_launcher_icon or the default app icon ?
Check your drawables and if its not there ,store one in it.
Then you'll definitely see your Action Bar title on the right side of your app icon.
For doing so below is my code hope it will hepl you..
actionbar.setDisplayShowCustomEnabled(true);
actionbar.setDisplayUseLogoEnabled(false);
actionbar.setDisplayShowHomeEnabled(false);
actionbar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
actionbar.setCustomView(getLayoutInflater().inflate(R.layout.actionbar_bg, null),
new ActionBar.LayoutParams(
ActionBar.LayoutParams.WRAP_CONTENT,
ActionBar.LayoutParams.MATCH_PARENT,
Gravity.CENTER
)
);
and create your custom view,what ever you want using xml file.
below is my xml-
<?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="#color/btn_bg_color">
<ImageButton
android:id="#+id/left_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp"
android:visibility="gone"
android:contentDescription="#string/app_name"
android:background="#android:color/transparent"
android:src="#drawable/refresh_btn"/>
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name"
android:textColor="#color/white_color"
android:textSize="18sp"
android:padding="5dp"
android:layout_centerInParent="true"
android:gravity="center_horizontal"/>
<ImageButton
android:id="#+id/right_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp"
android:layout_alignParentRight="true"
android:contentDescription="#string/app_name"
android:background="#android:color/transparent"
android:src="#drawable/logout_btn"/>
</RelativeLayout>

Android translucent card/layout like timely app

I'm trying to copy this layout out of the beautiful Android Timely app
Specifically, the translucent box that has all the alarm info inside it. Not sure if it's a layout with a slightly different fill color than the background with the alpha value set really high.
I do something like this:
Manifest.xml
<activity
android:theme="#style/PopupTheme"
android:configChanges="orientation|screenSize"
android:name="your.package.Activity">
</activity>
Styles.xml
<style name="PopupTheme" parent="Theme.AppCompat.Base.CompactMenu.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:background">#android:color/transparent</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:windowIsFloating">true</item>
</style>
Color.xml //You can play with the alpha value
<color name="transparent_black">#A0000000</color>
myLayout.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/transparent"
android:gravity="center">
<LinearLayout
android:id="#+id/root"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="20dp"
android:gravity="center"
android:background="#color/transparent_black">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#android:color/transparent"
android:layout_marginTop="30dp">
<Button
android:id="#+id/guardar"
style="#style/boton_aceptar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/action_save"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
And the result: the white part it's gonna be the current screen in the phone.

Android custom alertdialog different on ICS and Gingerbread

I have a custom alertdialog that inflates this custom layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/infoLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:theme="#style/AppTheme" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:weightSum="2" >
<TextView
android:id="#+id/infoVersionTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right|center"
android:text="#string/infoVersion"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/infoVersionTitleValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<TextView
android:id="#+id/infoDetailText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout1"
android:padding="10dp" />
</RelativeLayout>
I have this in my manifest file:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
........
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
And I've got style.xml defined this way:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="android:Theme.Light"></style>
</resources>
style.xml v11 defined like this:
<resources>
<style name="AppTheme" parent="android:Theme.Light"></style>
</resources>
And style.xml v14 defined like this:
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar" />
</resources>
When running this on a 4.0.3 device it shows like this:
And running on a 2.3.3 device it shows like this:
On 2.3.3 devices, text is almost unreadable and I want to show white background (title bar included)
Is it possible to make the custom alertdialog show on all devices like it shows on 4.0.3?
I've saw this but cant't seem to figure it out.
Any solutions?
Try calling AlertDialog.Builder#setInverseBackgroundForced(true) when you create your dialog.
You can use ActionBarSherlock for this purpose
Check the description in Theming page for Dialog
To ensure compatibility for all devices:
setInverseBackgroundForced(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? false
: true)
This makes sure devices below HoneyCromb display normally and devices below are inverted!
Here is an example:
final AlertDialog.Builder dialog = new AlertDialog.Builder(this)
dialog.setInverseBackgroundForced(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? false
: true);
dialog.setMessage("Test Dialog!");
dialog.create().show();
See the docs:
http://developer.android.com/reference/android/app/AlertDialog.Builder.html#setInverseBackgroundForced(boolean)

Categories

Resources