I would like to set the background of my activity to an image without setting the ActionBar background to the same image. I started with a "Hello, world" application with EditText, Button and an ActionBar and the following styles added...
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBarTheme</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:background">#drawable/bg20140804_090625_640_960</item>
</style>
<style name="MyActionBarTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:background">#android:color/transparent</item>
</style>
</resources>
Here is the application manifest...
<uses-sdk android:minSdkVersion="11" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.company.android.mysecondapplication.MainActivity" />
</activity>
</application>
The problem I am seeing is that the background image is shown in the ActionBar (distorted). I would like the ActionBar to be semi-transparent and for the background of the Activity to show through.
This is what it looks like, notice the ActionBar background. Also notice the icons are way over to the left when normally (i.e., without the custom style), they would be to the right.
Lastly, if you change the styles to the following, the application looks like the tutorial.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
</style>
</resources>
Thanks
Change
<item name="android:background">#color/your_color</item>
with
<item name="android:windowBackground">#color/your_color</item>
You can use #drawable/your_drawable of course.
Set the background image to the layout of your Activity and not to the Theme, that will result in only the Activity having the image as the background.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/bg20140804_090625_640_960" >
</LinearLayout>
Related
I am a beginner of android,Kotlin,
I don't know how to remove the top app bar in a specific and all activities.
I have a splash screen and a new activity
Below is my style's code,I already imported a material design in styles.xml
I don't know what is the way to remove the top app bar in styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
</resources>
Android Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.shanjostech.newsample">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".Main_Screen"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Add theme attribute to the activity where you want to hide appbar in manifest file
<activity
android:name="com.mvvm.Activity"
android:label="#string/app_name"
android:theme="#style/NewTheme">
</activity>
then create a new theme in style.xml with parent as Theme.AppCompat.NoActionBar
<style name="NewTheme" parent="Theme.AppCompat.NoActionBar">
</style>
This question is already answered here:-
How to remove it from all activities
How to remove it from specific activity
In Case if none of them work fine for you then try this:-
For specific activity,
Set theme in manifest file as mentioned below:-
<activity android:name=".activity.ContinueLoginActivity"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
android:screenOrientation="portrait" />
Programmatically :-
Kotlin:
supportActionBar?.hide()
Java:
if (getSupportActionBar() != null) {
getSupportActionBar().hide();
}
for remove it from all activities change .DarkActionBar by .NoActionBar in style.xml file:-
<resources>
<!-- Base application theme. -->
<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>
</style>
i define two theme in styles.xml
AppTheme1 and AppTheme2:
<resources>
<!-- Base application theme. -->
<style name="AppTheme1" 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>
</style>
<style name="AppTheme2" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#00ff00</item>
<item name="colorPrimaryDark">#ff00ff</item>
<item name="colorAccent">#0000ff</item>
</style>
</resources>
when i change theme in application tag inside AndroidManifest.xml
my app theme doesn't any change and the app only use colors.xml and not styles.xml.
for example my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.maneshtsoft.blackdictionary">
<application
android:allowBackup="true"
android:icon="#mipmap/favicondark"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme2">
<!-- OR AppTheme1 does not matter -->
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
just say that i use toolbar and AppCompactActivity maybe help to answer.
thanks.
The problem may be the cache of InstantRun.
Did you try "Clean & Rerun"? If you use AndroidStudio 2.1 or higher, Select Menu -> Run -> Clean & Rerun.
On the youtube app when you go to someone's channel the top bar changes color.
It goes from red to some other color
How do they get it to change color multiple times throughout the app? What is the code behind it? I would like to do a similar thing in my android app.
There are two ways to do this.
Dynamically
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.BLUE);
}
Styles
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item> <!-- statusbar color -->
</style>
<style name="RecyclerTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/primary_recycler</item>
<item name="colorPrimaryDark">#color/primary_dark_recycler</item>
</style>
</resources>
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.eugene.eugenehoranresume"
xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name=".Activities.HomeActivity"
android:label="#string/title_activity_home"
android:theme="#style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".Activities.RecyclerExample"
android:label="#string/app_name"
android:theme="#style/RecyclerTheme">
</activity>
</application>
</manifest>
My theme is not working I have seen this How do I change the background color of the ActionBar of an ActionBarActivity using XML? but not working
still grey only SplahScreen activity changed but MainActivity extend FragmentActivity not:
Manifest:
<application
android:largeHeap="true"
android:name="asasdsd.asdasdas"
android:allowBackup="true"
android:icon="#drawable/ic_launcher2"
android:label="#string/app_name"
android:theme="#style/MyTheme"
>
<activity
android:name="app.sultan.sdcinfo.SplashScreen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="app.sultan.sdcinfo.MainActivity"
android:label="#string/app_name"
android:theme="#style/MyTheme"
>
</activity>
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21" />`
I have localization and add theme file in every Language also in value-11 still not changed:Theme.xml
`<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#262626</item>
</style>`
Tried with getActionbar.setBackgroundDrawable(new ColorDrawable("COLOR"));
please look my project structure:splash screen activity then Main activity wich include navigation drawer with fragments in activitis color background changed but not in the fragment
You could not be able to change the actionbar background color because you are not using Widget.Holo.Light.ActionBar.Solid.Inverse as the parent of MyActionBar
use
parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse"
instead of
parent="#android:style/Widget.Holo.Light.ActionBar
So your theme.xml would be like,
<resources>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#262626</item>
</style>
</resources>
Source : Customize ActiobBar Background (Official Documentation)
In my application I have a lot of layers and instead of setting a background image to each of them, I want to set a background once and for all. How can I do that?
Take a look at Apply a theme to an Activity or application to apply the background image across the whole application.
Add android:windowBackground to your theme:
<!-- 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">#color/colorPrimaryDark</item>
</style>
And of course make sure your manifest uses the theme for you application:
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.package.name"
xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>