Activity background in Android - android

I have an activity with background colour black.
It has edittext and right after soft keyboard goes away, for a moment I see white area under keyboard; and then view gets resized.
This looks like blinking.
Question is, is it possible to set some kind of default background color for entire app? (Assuming that my activity already has background attribute)
windowSoftInputMode is also not an option

If you want to specify the background to your whole application, you may edit the app theme or add custom theme to your application manifest. But this will be overridden when background is specified in the xml layout.
Add custom theme in style.xml
<style name="MyTheme" parent="android:Theme">
<item name="android:background">#android:color/black</item>
</style>
Specify the theme in manifest as
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/MyTheme" >
Adding theme for each activity in manifest
<activity
android:name=".Login"
android:configChanges="orientation"
android:theme="#style/MyTheme>
</activity>
You can also modify the existing theme in style.xml which is already defined in manifest by changing the background as desired
<item name="android:background">#android:color/black</item>

Related

Changing background color in a activity.

I used Android Studio to create basic activity using New -> Activity -> Basic Activity. But the activity background colour is black. I know it is to reduce battery consumption. But is there a way to change it to white colour, without changing style.
I tried to change the background colour of the root layout, but then it won't show hint text of edit text field. Because it's colour is white.
Then I tried to change theme from Material to Material Lite, then it wouldn't show the change when I run the app in the device.
Here is the activity declaration in AndroidManifest.xml
<activity
android:name=".SearchBus"
android:label="#string/title_activity_search_bus"
android:parentActivityName=".MapsActivity"
>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="uk.co.stableweb.iroute.MapsActivity" />
</activity>
In your styles.xml set the android:windowBackground attribute for whatever theme you are using for application or activity. You can find the theme you are using in your AndroidManifest.xml.
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowBackground">#color/somecolor</item>
</style>
</resources>
Note: If you have views in your layout that aren't transparent, it will block you from seeing the color you set here.
Did you try :android:background="#ffffff" i? It works for me

Android - Disable dummy starting window of application

I want to know how to achieve this effect.
My app (default everything), when launcher icon is clicked, right away display some kind of a empty dummy window, where nothing is happening and then loads layout into it.
"Heavier" apps like YouTube, Drive, Dropbox etc. when started, seem to wait after launch, without showing that dummy window and load right into ready layout.
Any idea how to do this or where should I look into?
Thanks
//EDIT: this has nothing to do with something like loading database, where I should display progressBar, imho this has to do with stuff before activity exists.
I suggest you don't disable the dummy loading window using:
<style name="Theme.MyTheme" parent="android:style/Theme" >
....
<item name="android:windowDisablePreview">true</item>
....
</style>
because you could run into several problems. For example, if you try to animate an AlertDialog, enter animation will not work (personal experience).
The right solution is to set the theme of your application like to your main activity screen (same ActionBar style, same background color).
In my application after severals experiments i found the right solution for my needs.
(I have a main activity with blank background, no ActionBar, just full screen personal layout)
1 - styles.xml: add new style like this (remove ActionBar and set the same background color of my main activity)
<style name="LoadingTheme" parent="#android:style/Theme.Light.NoTitleBar.Fullscreen">
<item name="android:windowBackground">#color/white_smoke</item>
</style>
2 - AndroidManifest.xml: set my theme for main activity to "LoadingTheme"
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.company.appname.MainActivity"
android:label="#string/app_name"
android:theme="#style/LoadingTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
....
</application>
And finally i have full blank dummy loading window without ActionBar with soft MainActivity load and working animations.
Hope to be helpful.
<style name="Theme.MyTheme" parent="android:style/Theme" >
....
<item name="android:windowDisablePreview">true</item>
....
</style>
but use with caution
This will create a custom preview window for your activity.
Create a style in styles.xml like
<style name="MyTheme" parent="#android:style/Theme.Holo.NoActionBar">
<item name="android:windowBackground">#color/myBackgroundColor</item>
</style>
In your Manifest file use the theme created above.
For eg:
<activity android:name=".MyActivity"
android:label="#string/app_name"
android:theme="#style/MyTheme"
/>
In your activity change the background of the window back to null in onCreate()
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setBackgroundDrawable(null);
setContentView(R.layout.main);
}
You can call the setContentView method anywhere you'd like in your activity. Before calling this method it will display a blank screen. If you wanted a splash screen, you can call the setContentView method within the onCreate method to display the splash screen view. Then when you're ready to display the "main" view you can use a LayoutInflater to display it. I also suggest using a ProgressDialog to show the user that information is loading.
Load your resources before setting the contentview. There will be a dummy window until you would not set view using setContentView.
EDIT
To avoid this screen. Make there changes to your code.
1) Do not do any heavy work in activity onCreate method. Run a separate thread for it.
2) Set content view right after the super.onCreate() line
super.onCreate(savedInstanceState);
setContentView (R.layout.splash_screen);
3) Apply following theme to your application.
Define theme in style
<resources>
<style name="Theme.MyTheme" parent="android:style/Theme" >
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowBackground">#drawable/any_default_background</item>
</style>
</resources>
In your Manifest
<application
....
android:theme="#style/Theme.MyTheme"
....
>
Thats It.

Why my PreferenceScreen is showing white instead of the default black?

I am testing my app but when I choose settings my preferences screen shows White instead of the default black theme. Just with my app because any other app shows the right black theme in preference screen.
<style name="PreferencesTheme">
<item name="android:background">#000000</item>
</style>
add the above code in value -> styles and
then add
<activity android:name=".Preferrence" android:theme="#android:style/Theme.Black"></activity>
in your manifest file it will solve your problem :)
I guess you using the Light Theme in your AndroidManifest.xml. For those PreferenceActivity set the Theme like this:
<activity
android:name="PreferenceActivity"
android:theme="#android:style/Theme.Holo" >
</activity>

Android: Changing the windowBackground of PreferenceActivity causes weird effect

I want to add a background image to my preference activity.
I tried by creating custom Theme:
<style name="MyPreference" parent="android:Theme.Light.NoTitleBar">
<item name="android:windowBackground">#drawable/preference_background</item>
</style>
and in the Manifest:
<activity android:name="SettingsActivity" android:theme="#style/MyPreference">
...
</activity>
But for some reason that caused to the PreferenceScreen to have a transparent background, like that:
Any idea how can i overcome that?

How to hide title bar from the beginning

I am using following code to replace title bar.
final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
And it's working fine once UI loaded. Problem is however when I start the app, the ugly gray bar appears for 1-2 seconds until UI loaded. Is there any way to specify not showing the default title bar at all?
If you want the titlebar to be gone in every activity within your app, then add
<application android:name=".YourAppNameHere"
android:label="#string/app_name"
android:icon="#drawable/icon"
android:theme="#android:style/Theme.NoTitleBar">
to your manifest. Not 100% sure though that this will prevent the titlebar from showing up momentarily, but it should work.
In the Manifest file, add this line inside the application tag
android:theme="#android:style/Theme.NoTitleBar"
It will hide the bar from all the activities. If you want to hide it from a specific activity, add the same line to that activity's tag.
Good Luck !
You should add a line to your AndroidManifest which states that you use a theme (standard android or extended)
<application android:name=".YourAppNameHere"
android:label="#string/app_name"
android:icon="#drawable/icon"
android:theme="#style/MyTheme">
and then you can have a themes.xml in your res/values/ folder where you extend the: Theme.NoTitleBar and add custom rules to them (for example like windowBackground)
<resources>
<style name="MyTheme" parent="android:Theme.NoTitleBar">
<item name="android:windowBackground">#drawable/my_background</item>
</style>
<resources>
Have fun

Categories

Resources