Android normal button turns transparent - android

I have a RelativeLayout with a background set with android:background="#drawable/background".
In my RelativeLayout` I have a standard button but when I run the app in devices running 3.1 or higher the button are displayed transparent.
I have tried setting android:alpha to 1 with no luck.
I know I can make a custom background with selector and shapes but there has to be another way.
Anyone else had this problem?

You'll want to add something like this to your style.xml
Application theme
<style name="ApplicationStyle" parent="android:Theme">
<item name="android:buttonStyle">#style/MyButtons</item>
</style>
Button style
<style name="MyButtons" parent="#android:style/Widget.Button">
<item name="android:textSize">16sp</item>
<item name="android:background">#000000</item>
</style>
Make sure you're setting your theme correctly in the manifest also
<application
android:allowBackup="true"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:theme="#style/Theme.ApplicationStyle" >

Related

Is it possible to customize the menu items by background color and padding?

I'm trying to do something like the mockup below. I need the first item to have a different background than the others. I also need this first item to be unclickable. I tried the enabled="false" attribute but that greys out the text which I don't want. Also I have tried itemBackground in styles.xml to change the item background color but this changes all of them and I only want the first item to have a different background. And lastly, I'd like some indentation in the last two items (not sure if this is even possible as I don't see padding and margin attributes).
Add popupMenu style to ur AppTheme:
<style name="AppTheme" parent="android:Theme.Light">
<item name="android:popupMenuStyle">#style/PopupMenu</item>
</style>
<style name="PopupMenu" parent="#android:style/Widget.PopupMenu">
<item name="android:popupBackground">#android:color/white</item>
</style>
manifest.xml:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
.............
</application>

How to keep same background in the whole application?

How can I make my application have the same background everywhere? I've tried to do it with editing the theme but the problem there was that my app uses an animation in which, when you go to an new layout it slides over. So want I want is a way to have the same background everywhere and when a new layout slides in only textviews and buttons and sh*t should move. The background has to stand still at the same position.
Also, what is the best size for an background within an app? 1080x1920 is a bit slow :P
THANKS!!
What i've tried: (values/styles.xml)
<resources>
<!-- Base application theme. -->
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="#style/Theme.AppCompat.Light">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:background">#drawable/background</item>
</style>
(androidmanifest)
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat.Light.NoActionBar.FullScreen" >
// unimportant things here
</application>
You can just set the background you need in the config file. Once you've done that, simple make sure you don't set the background anywhere else and you should be okay.

Changing Android action bar background colour

For some reason this setup just gives me the default action bar background colour.
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#d73830</item>
</style>
</resources>
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
...
</application>
In activity_main.xml my theme is set to 'AppTheme'.
You have wrong parent of MyActionBar.
It must be from AppCompat, like next:
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background" tools:ignore="NewApi">#color/red</item>
<item name="background">#color/red</item>
</style>
What you can do is to use hash code of colour.Here is how.Go to this web page
http://www.color-hex.com
Choose a colour you wish and after copy the code of that colour and later paste into your background section.In general lets say you want your background colour of your screen to be red so you must declare it in xml layout file like this
android:background = "#FF0508"/>
You can declare this code almost everywhere where you want to change exact things colour and for my opinion its the easiest way.Why not?you got a webpage where you can get colour code and you can use it with a single line everywhere.Delicios isn't it?

Why there is a white screen appears for 1sec when starting to run the apps in Android?

When I click the app icons and start to run the apps, it will appear a white screen for 1 sec.
I don't know why.
Is there any idea to clear this white screen and directly go to my activity?
The white/black screen is the window background image.
The window background is shown while e.g. your onCreate() runs and your layouts are being inflated. It can take some time especially if there's a lot of bitmaps that need to be read, decoded and scaled.
Changing the theme works because some themes have a non-default window background. For example, Theme.Wallpaper has a transparent background. There are other definitions there, too. Essentially what you want is:
<style name="YourTheme">
<item name="android:windowBackground">#null</item>
</style>
Programmatically you can achieve the same with
getWindow().setBackgroundDrawable(null);
at the top of activity onCreate().
(Old question but got bumped up by another answer and there wasn't a good answer.)
Settings. File>Settings>Build,Deployment>Instant Run Deselect all options shown there.
and add below line in your style.xml
<item name="android:windowDisablePreview">true</item>
<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:windowFullscreen">true</item>
<item name="android:windowDisablePreview">true</item>
</style>
apply changes in AndroidMainfest.xml
<application
android:theme="#style/AppTheme">
After I change style.xml:
<resources>
<style name="AppTheme" parent="android:Theme.Wallpaper" />
</resources>
it works!!
Thanks all
Add the following in the manifest file of the corresponding activity
android:launchMode="standard"
and remove android:label="#string/app_name" from the corresponding activity ,this actually helped me
In your manifest.xml file remove the line android:theme="#style/AppTheme" for your app. and check it again
Use this tag in your manifest:
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
In Styles add the following things
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowIsTranslucent">true</item>
Hope this will help you and its working for me

set background Image to whole application in android

I want to set background image to my application in android. So my application already has a theme set in my manifest file like this
<application android:theme="#android:style/Theme.NoTitleBar" />
Now this was implemented from the themes of android package.
Now i want to add a background image to my entire application how can i do it.
<style name="Theme.NoTitleBar.BackgroundImage">
<item name="android:background">#drawable/bitzer_background</item>
</style>
I want the Theme.NoTitleBar as well.
I have changed the style below, 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 my manifest file looks like this:
<application android:theme="#style/Background"/>
You have to use styles to achieve this
Check out this link
Create a theme with your background and use that theme.

Categories

Resources