Hi i want to set background image to my application which already has a theme.
<application android:theme="#android:style/Theme.NoTitleBar" />
Now i have changed the code to this
<style name="BackgroundImage" parent="#android:style/Theme.NoTitleBar">
<item name="android:background">#drawable/background</item>
</style>
the manifest file looks like this
<application android:theme="#style/BackgroundImage" />
Now the background image is set but my previous theme i.e. Theme.NoTitleBar is not working.
Ideal behavior expected is both background image and Theme.NoTitleBar should be working. What should i do?
I have changed the style as follows by doing this i am overriding the Theme.NoTitlteBar
<style name="Background" parent="#android:style/Theme.NoTitleBar">
<item name="android:windowBackground">#android:color/black</item>
<item name="android:windowNoTitle">true</item>
</style>
Now manifest file looks like this.
<application android:theme="#style/Background"/>
you need to do it in the xml file, and not your manifest.
you just have to do somerhing like this:
<?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"
android:background="#drawable/yourimage" > //your drawable image here
hope i helped you
Related
We developing home screen widgets in 2021 and I tried to implement dark theme support.
According to https://developer.android.com/guide/topics/ui/look-and-feel/darktheme#widgets
"... use appropriate theme attributes instead of hardcoded colors."
So as I understand I can use custom attributes and I added attrs.xml in values folder
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="customBackgroundColor" format="color" />
</resources>
After that I added my custom attribute to light/dark theme
values/themes.xml
<resources>
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
<item name="customBackgroundColor">#color/white</item>
</style>
</resources>
And also for dark
values-night/themes.xml
<resources>
<style name="AppTheme" parent="Theme.MaterialComponents">
<item name="customBackgroundColor">#color/black</item>
</style>
</resources>
Here is my widget layout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/customBackgroundColor" />
When I placing widget on home screen I got "Problem loading widget" message.
When I tried to hardcode colors for layouts, everything works as expected.
I also tried using default attributes "colorPrimary" and there was no error message but widget not changing color according to theme I switched.
Do I missing something or information in official docs is incorrect?
I'm trying to add splash-screen to my Android app.
I've been following instructions from here. It's the standard way as I get it, and it seems logical.
So it's really simple right? Create drawable resource, use it in a theme as windowBackground, use the theme? Well it doesn't work for me...
manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="euroicc.sicc">
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme.Splashscreen">
<activity android:name="euroicc.sicc.ui.MainActivity"
android:theme="#style/AppTheme.Splashscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
styles:
<resources>
<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="android:spinnerDropDownItemStyle">#style/mySpinnerItemStyle</item>
<item name="android:itemBackground">#color/main_background</item>
<item name="android:textColor">#color/text_default</item>
<!--<item name="android:popupMenuStyle">#style/MyAlertDialog</item>-->
</style>
<style name="AppTheme.Splashscreen" parent="AppTheme">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowBackground">#drawable/splashscreen_drawable</item>
</style>
</resources>
splashscreen_drawable:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#android:color/holo_green_light"></solid>
</shape>
</item>
<item>
<bitmap android:src="#drawable/splashschreen_eicc"
android:gravity="center"></bitmap>
</item>
</layer-list>
I've tried other codes from other sites, but nothing seems to work.
Only white background is displayed for less then a second (approximately), and then the app starts running. I'm setting the theme AppTheme in onCreate method of main activity so it uses it's default theme always except on start.
I'm also overriding onPause and onResume, but I call their supers, so that shouldn't be a problem.
I'm testing on v7.0.0, but that shouldn't be a problem also?
I have more styles but I removed them from the example code, because they are used for dialogs and elements inside xml files, not for activities.
So what is the problem and how do I solve it? When I first read about splashscreens I thought setting windowBackground would've been enough
You don't set your background in styles.xml, rather inside your splashcreen layout xml file. Here is my layout example:
<?xml version="1.0" encoding="utf-8"?>
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="ContentDescription"
android:background="#drawable/green" ==============================> HERE!
tools:context=".activity_splash_screen">
<ImageView
android:id="#+id/logo"
android:layout_width="#dimen/_150sdp"
android:layout_height="#dimen/_150sdp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/_100sdp"
android:src="#drawable/white_logo"
/>
<ImageView
android:id="#+id/title"
android:layout_width="#dimen/_240sdp"
android:layout_height="#dimen/_150sdp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="#dimen/_100sdp"
android:src="#drawable/title"
/>
If you need help with the entire code, I can help you!
I've had this problem. I created the splash screen as a layer-list drawable, and in the theme as windowBackground as it is recommended everywhere, yet it wouldn't work on some devices (like my and my friend's Motorolas, a few other phones) - a black screen would be shown. For me the solution was to wrap my splash activity code in a Handler's postDelayed runnable with some small delay:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Handler(Looper.getMainLooper()).postDelayed( { //this is a trick so the splash screen - in window bg theme - is displayed on all devices, instead of black screen. E.g. moto g6
val startMainActivityIntent = ...
startActivity(startMainActivityIntent)
finish()
}, 100)
}
I am not particularly fond of delaying UI, if I knew a better way that worked, I would not do this. But it’s better than black screen.
In continues to this question, I'd like to change the colors of both the actionbar (the upper pane)to one color and the rest of the screen to a different color.
How can I do it?
when I tried this -
<style name="MyTheme" parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:background">#ffffd982</item>
</style>
it seems like the 'android:background' definition override also the actionbarstyle definition
Indeed, the background attribute is known to supersede the actionBarStyle attribute. However, changing the color of the entire Activity needs to be done through the Activity's XML layout, using the android:background attribute of the parent ViewGroup. The ActionBar styles won't help you there.
In your Activity's root ViewGroup, set the background attribute as:
<LinearLayout
android:id="#+id/outermost_viewgroup"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background = "#00FF00"
....
....
EDIT:
I just realized that there is a way for this:
<item name="android:windowBackground">#color/background</item>
Add the above tag to to your ActionBar style definition, and the background in the colors.xml file:
<resources>
<color name="background">#00FF00 </color>
</resources>
There, done!
To change Actionbar style In your style.xml file define style like bellow
<style name="AppBaseTheme" parent="android:Theme.Light">
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.ActionBar">
<item name="android:background"><YourColor></item>
<item name="android:titleTextStyle"><Your String Color></item>
</style>
In your menifest.xml file used your style inside application tag like bellow
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
And for set background color of your activity just set android:background attribute in your each activity like
<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="#ff2323"
tools:context=".MainActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_below="#+id/textView2"
android:layout_marginTop="121dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
I think this is work for you...!
I'm trying to implement the ViewPagerIndicator with SherlockActionBar. It works: I can slide the fragments, but the style doesn't work!
It looks like this:
related topic: https://github.com/JakeWharton/Android-ViewPagerIndicator/issues/66
I know what's going wrong:
In the sample of VPI, the style of a page is set in AndroidManifest.xml by (for example)
<activity
android:name=".SampleTabsDefault"
android:theme="#style/Theme.PageIndicatorDefaults">
</activity>
But when I add that android:theme element to my own Manifest.xml I get the following exception:
03-16 11:06:24.400: E/AndroidRuntime(483): Caused by: java.lang.IllegalStateException: You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative.
I've also tried to copy all the style-information to styles.xml, but that also doesn't work.
Can you tell me how to set a style to the VPI?
Thank you!
EDIT:
Now I've added
<activity
android:name=".SampleTabsDefault"
android:theme="#style/StyledIndicators">
</activity>
to my Manifest.xml
and the following style in styles.xml
<style name="Theme.BataApp" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
</style>
<style name="StyledIndicators" parent="Theme.BataApp">
<item name="vpiTitlePageIndicatorStyle">#style/Widget.TitlePageIndicator</item>
<item name="vpiTabPageIndicatorStyle">#style/Widget.TabPageIndicator</item>
<item name="vpiTabTextStyle">#style/Widget.TabPageIndicator.Text</item>
</style>
Result: I don't get any Exception, see the style, but I now I can't see any fragments :(
The code of the activity can be found here: http://pastebin.com/hsNgxFDZ
Screenshot of current page with style:
In order to see the Fragments, you'll have to somehow extend an Android base-theme. In order to see the ViewPagerIndicator, you'll have to somehow include those style-definitions. The answer is to create your own theme that extends the ActionBarSherlock-theme (which extends the Android base-themes), and implements the ViewPagerIndicator-styles.
Example:
<style name="myTheme" parent="#style/Theme.Sherlock">
<!-- If you want to use the default ViewPagerIndicator-styles, use the following: -->
<item name="vpiTitlePageIndicatorStyle">#style/Widget.TitlePageIndicator</item>
<item name="vpiTabPageIndicatorStyle">#style/Widget.TabPageIndicator</item>
<item name="vpiTabTextStyle">#style/Widget.TabPageIndicator.Text</item>
<!-- If you want to implement your custom style of CirclePageIndicator, do it like so: -->
<item name="vpiCirclePageIndicatorStyle">#style/myCirclePageIndicator</item>
<!-- Put whatever other styles you want to define in your custom theme -->
</style>
<style name="myCirclePageIndicator" parent="Widget.CirclePageIndicator">
<item name="fillColor">#color/my_custom_circle_indicator_fill_color</item>
</style>
Then in your Manifest, set android:theme="#style/myTheme" to the <application> or to your <activity>s.
Note that you don't have to include all 4 "vpi..."-styles; you only have to include those that you use. E.g. if you're only using the CirclePageIndicator, you only have to include <item name="vpiCirclePageIndicatorStyle">...</item> and can leave out the other 3 item declarations.
I accidentally removed android:layout_weight="1" when adding styles.
So for other who want to implement VPI with ABS:
layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.viewpagerindicator.TabPageIndicator
android:id="#+id/indicator"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
style="#style/StyledIndicators" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>
styles.xml:
<style name="Theme.BataApp" parent="Theme.Sherlock.Light.DarkActionBar">
etc.
</style>
<style name="StyledIndicators" parent="Theme.BataApp">
<item name="vpiTitlePageIndicatorStyle">#style/Widget.TitlePageIndicator</item>
<item name="vpiTabPageIndicatorStyle">#style/Widget.TabPageIndicator</item>
<item name="vpiTabTextStyle">#style/Widget.TabPageIndicator.Text</item>
</style>
Thank you #Reinier! :D
The blue shadow over scroll effect looks really ugly in our app.
Is there a way to disable all the over scroll effect? You know there are lots of ScrollViews and Lists in it... That would be a shame if I have to disable it in every widget that can
scroll...
thx~
You can do it simply
In layout.XML
Set
android:overScrollMode="never"
In scrollview
You can define a ScrollViewStyle and ListViewStyle in your Theme:
<style name="Theme.MyTheme" parent="android:Theme.Holo">
<item name="android:listViewStyle">#style/Widget.MyTheme.ListView</item>
<item name="android:scrollViewStyle">#style/Widget.MyTheme.ScrollView</item>
</style>
<style name="Widget.MyTheme.ListView" parent="android:Widget.ListView">
<item name="android:overScrollMode">never</item>
</style>
<style name="Widget.MyTheme.ScrollView" parent="android:Widget.ScrollView">
<item name="android:overScrollMode">never</item>
</style>
Then you have to define your Theme in you AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ch.citux.example"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:targetSdkVersion="16" android:minSdkVersion="8"/>
<application
android:hardwareAccelerated="true"
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:theme="#style/Theme.MyTheme">
That's it, no more overscroll ;)
I have face same problem
try this code
listView.setOverScrollMode(View.OVER_SCROLL_NEVER);
You can disable all the over scroll effects by opening "res/values/styles.xml" file and adding the item line like bellow:
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:overScrollMode">never</item>
</style>
Have you already used setOverScrollMode, with OVER_SCROLL_NEVER?