Android want to create a transparent menu - android

I have seen some posts regarding transparent menu.
I am able to change the background color of menu using the code given in the following link - Customizing the Options Menu Background
When I tried to change the background as transparent in the same code like given below, its not working
view.setBackgroundResource(R.drawable.full_trans_bg);
instead of a normal image I have tried the transparent image, but its not working.
I just want to change the background color alone not the rest. Bcas I know to get this transparent background by inflating a new layout in the onCreateOptionsMenu() but in this case I want to do everything manually, which is not a motive.
Thanks in advance.

Create a style in styles.xml
<style name="myApplicationCustomTheme" parent="#android:Theme">
<item name="android:panelFullBackground">#android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
</style>
Apply this to your manifest
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/myApplicationCustomTheme"
android:debuggable="true"
>
Also refer to this post. Is it possible to make the Android options menu background non-translucent?

I don't know the full code, but try something like this:
view.setBackgroundResource(new Drawable(new Bitmap(R.drawable.full_trans_bg).getBitmapdata());
That might help.

You can use XML background color value #00ff0000 which is transparent in itself.

Related

Background Recyclerview shows incorrectly after changing to Light/ Dark theme from Android App

Anyone can help me?
I'm developing the Light and Dark theme function in the android app, everything goes fine, but the background of Recyclerview shows incorrectly.
The root background of xml file is White color and I didn't set background for recyclerview in xml. However, after changing from Light to Dark or Dark to Right=> background of recyclerview automatically change to a strange color(this color didn't see in my color.xml resource). I tried to set background of Recyclerview to #null or transparent in code and xml file as well but the background of recyclerview didn't remove that strange color.
So anyone knows exactly the reason why, please help me and much appreciated. Thanks
enter image description hereenter image description here
I am guessing you are using the DayNight Theme. If so you should have to themes.xml folder in res, one is called as mentioned and the other is with the extension (night). There you can define a color in both xml files. It has the same name but different color values like this:
<style name="AppTheme" parent="Theme.AppCompat.DayNight">
<item name="colorPrimaryDark">#ffffff</item> <!-- you normally shouldn't hardcode color -->
</style>
The same for your folder (night):
<style name="AppTheme" parent="Theme.AppCompat.DayNight">
<item name="colorPrimaryDark">#000000</item> <!-- you normally shouldn't hardcode color -->
</style>
The idea is to have one attribute name that contains 2 colors and takes the correct one if needed. For futher understanding I suggest to take a look at this reference to get more familiar with Themes and Styles. Now you set up your Day and Night files properly, you can implement it by using it in your recyclerView as follows:
android:background="?attr/colorPrimaryDark"
Another tip is to make custom colors in multiple colors.xml files to make them for more unique use. In this case colorPrimaryDark effect your whole app. It is also suggested to modify layouts and the visuals of widgets to take effect only on those. (e.x. your recyclerView). In my app I used colorPrimaryDark for all Background (that should be same for more clean design). I think you get the keypoint. Take a look around the net and this forum and you will find your final design strategy. Cheers! :)

Make transparent background in xml

I have android scanner project and its totally working to me .I ask and search a lot but it is not the thing that i want. What i want to do is to make my layout background Transparent like this
https://i.stack.imgur.com/jFovP.png
They suggest to me to use :
android:background="#android:color/transparent"
but what happen is it just make my background White(#ffff), you can see here in this picture https://i.stack.imgur.com/gCkoi.jpg my backgroud is Blue but what I'm trying to do is the first picture above .
Thank you in advance for the answer.
If your xml Layout Background is Transparent it's Still not enough to make the Background of an Activity Transparent. You Need to Add these to your Style:
<style name="Transparent" parent = "Theme.AppCompat.Light.NoActionBar">
...
<item name = "android:windowIsTranslucent"> true </item>
<item name = "android:windowBackground"> #color / transparent </item>
...
</style>

Android activity Background affects alertDialog

I have a style I created like this:
<style name="myStyle" parent="#android:style/Theme.Dialog">
<item name="android:textColor">#FFFFFF</item>
<item name="android:background">#000099</item>
</style>
Then I created an xml and an activity, and in the manifest declared this
<activity android:name=".Try"
android:theme="#style/myStyle" >
</activity>
Then when I start this activity I have an xml with a background color (blue);
THe problem is , when I create an Alert Dialog
AlertDialog.Builder dialog = new AlertDialog.Builder....
It is also affected by this background (It looks more like a blue rectangle behind it that is bigger then the dialog and is coming out from all 4 sides).
I dont want it to be, I want to use another style for the alert dialog.
How can I disable this?
Are you saying that the background of your activity is too prominent when the dialog pops up? If so, you can blur what's in the background with the following code:
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
Or are you saying that the background of your activity is being applied to the background of your dialog...?
I managed to fix that, well not entirley but to pass around it.
Instead of using:
#000099
I used
IMAGE_NAME
and I added a green rectangle image at the "drawable" folder.
This makes the background to become from an image instead of painting it, and the image does not affect the Dailog.
It will look a bit different (for example it will cover the white border as well) but it is better then before.

Android preference title/summary text style

I have a couple custom preference items -- one that displays a swatch of the currently selected color, and another one that displays a thumbnail.
I have a custom layout for these that matches up very well, and have found that I can make the text appearance match by using android:textAppearance="?android:attr/textAppearanceLarge" as part of the TextView's xml. The problem is, while these generally look fine, they must not be the appearance the 'official' preferences use, since the colors end up wrong on some devices. In particular I'm porting my application to the Nook Color, and it uses a light grey background and black text color on the preference screen instead of black background/light grey text. My text color in this situation stays the same, but the rest of my layout is themed appropriately.
I'm really unsure what I'm supposed to do here to make my text match up with the 'official' theme. Should I be using obtainStyledAttributes and running though my layout to set things? The tutorials I've seen on using that so far have been really baffling, and it seems like there must be a textAppearance or style I can set in the XML to fix this.
You've to define your own application theme which inherits from the official theme you want. Actually, you can just define a theme MyTheme extending the Theme.Light for example.
Create an res/values/styles.xml file like that:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="#android:style/Theme.Light">
</style>
</resources>
Then, you just have to apply your theme using the android:theme attribute of the application entity of your AndroidManifest.xml:
<application android:theme="#style/MyTheme">
[...]
</application>

Application background image with transparent activities

hope you guys can give me a hand now! this is tricky to me
I have run into an requirement of my application that i cant find a way to do this.
I need my application to be fullscreen and no title bar (done), and this application will have a background image. However, all the activities/views of my application must be transparent/translucent so the application background will be visible all the time behind the information i am displaying.
Basically i would like to have this behavior
http://www.geeky-gadgets.com/wp-content/uploads/2010/05/amazon-kindle-android-app.jpg
supousing that the image you see is not the phone wallpaper, but the application background image. What would be the application configuration in the manifest file and what would be the configuration for eacy activity/view?
I also noticed that, i need to setup each activity to be fullscreen without title bar. Is there a way to do this globaly in the application so all activities will behave this way?
Many thanks for your time
To hide the title bar in all your activities you should set a custom theme in your AndroidManifest.xml file like so:
<application
android:icon="#drawable/application_icon"
android:label="#string/app_name"
stuff..
android:theme="#style/MyTheme">
Then define the theme in styles.xml:
<style name="MyTheme" parent="android:Theme.Black">
<item name="android:windowNoTitle">true</item>
</style>
For the background, I'm pretty sure you can just set a the background of a ListView to point to a .PNG that you have in your resource folder (it probably has to be the exact dimensions of the screen).

Categories

Resources