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>
Related
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! :)
I want to change the overlay color of a dialog. The first which comes as transparent gray.
I tried:
<item name="android:windowContentOverlay">#color/customColor</item>
<item name="android:colorBackgroundCacheHint">#color/customColor</item>
They did not work. When I tried:
<item name="android:windowBackground">#color/customColor</item>
The content background is changing.
I found a one rule solution!
d.getWindow().setBackgroundDrawableResource(R.drawable.menubackground);
It works for me with a normal dialog.
But I dont know if it works on an AlertDialog.
I want to fully customize button in android, with keeping all its juicy material design styles.
Without a custom drawable png for button, just applying a color to button, i am able to change the color of the button and keep the Elevation, Ripple Effect, Rounded corner and it looks nice.
The code i used for this is
<resources>
<style name="AppTheme.NoActionBar">
<item name="android:colorButtonNormal">#8126f3</item>
</style>
</resources>
Then i wanted to put my own drawable into the button and keep the Material Design effects . so i created a drawable (V21) and assigned it as background to the button.
button_ripple.xml
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?attr/colorControlHighlight">
<item android:drawable="#drawable/take_ride_map_btn"/>
</ripple>
But now the problem is that it does not have a elevation. And the ripple effect does not start at the point of touch.
I have looked into this, this, and this SO Question but these are not helpful with using the custom drawable into button.
Please do suggest how can i achieve this -
Elevation while having the custom drawable.
Start the Ripple Effect at the point where user touches.
you can always have the elevation if you set the button to wrap_content both ways i.e height and width and for the ripple effect you should use RippleDecoratorView.
You don't need to cast it to anything just wrap the button inside it in xml and your good to go, plus its highly customizeable too
I'm starting with a fully working app, with all the buttons in the right locations and the right sizes... but now I wanted to try out using styles for the first time. In particular I wanted to have the text colour in my buttons a dark blue and the background white. So I wrote the following in styles.xml in res/values ->
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="mybut" parent="#android:style/Widget.Button">
<item name="android:textColor">#color/dblue</item>
<item name="android:background">#ffffffff</item>
</style>
</resources>
I modified my button code as follows:
<Button
android:id="#+id/spec"
style="#style/mybut" <-- I added this line here
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.12"
android:text="#string/spec" />
In eclipse's XML viewer, the new button looked right in every way. But then at run time, on my android device, the button's height had shrunk by about a third! Any ideas?
EDIT: I'm not very confident about the parent="#android:style/Widget.Button" bit. I'm suspicious that perhaps I'm somehow already using some other style?/theme? and perhaps the line should look something akin to parent="#android:otherstyle/Widget.Button" or parent="#android:style/other.Widget.Button"... or similar.
EDIT: FYI... I'm trying this out on a kind of "home screen" activity which just contains two big buttons. I added the style="#style/mybut" to just one of the two buttons. They are now clearly very different sizes.
EDIT: I noticed that in the manifest I have android:theme="#android:style/Theme.NoTitleBar.Fullscreen" ... does that mean I need to make my button's parent android:theme="#android:style/Theme.NoTitleBar.Fullscreen.Widget.Button" ?? or something like that?
By default, a Button has a 9-patch background, not a simple color. This image has padding and a content area which alters the actual size of the button.
When you change the background, you're stripping that padding, and it appears smaller. The correct way to do this is to create a new 9-patch, based on the old, but with the colors changed.
The problem must be here:
android:layout_weight="0.12"
If you have an action_bar or something like that when you run your app the button is going to shrink. In your preview the action_bar doesn't appear (I'm just guessing).
EDIT:
Here is a sample of a custom button that I use in my app, I put a min height and width.
Instead of using: parent="#android:style/Widget.Button" I use: parent="android:Widget.Button"
<style name="ButtonCustom" parent="android:Widget.Button">
<item name="android:background">#drawable/btn_default_holo_light</item>
<item name="android:minHeight">48dip</item>
<item name="android:minWidth">64dip</item>
<item name="android:textColor">#fff</item>
</style>
I have a progressbar with the following style: style="?android:attr/android:progressBarStyleSmall"
Sadly the bar is nearly white and in my case displayed on a white background.
The progressbar is nearly invisible because of that.
How can I change the color of the progressbar? A darker grey would be great.
progressBar.getIndeterminateDrawable().setColorFilter(
getResources().getColor(R.color.light_light_purple),
android.graphics.PorterDuff.Mode.SRC_IN);
This code changes the default holo inderminate drawable color to your own color.
Define your color code and replace R.color.light_light_purple to R.color.your_color_code.
To get a black ProgressBar, use one of the inverse styles:
<ProgressBar style="#android:style/Widget.ProgressBar.Inverse"/>
<ProgressBar style="#android:style/Widget.ProgressBar.Large.Inverse"/>
<ProgressBar style="#android:style/Widget.ProgressBar.Small.Inverse"/>
The reason why the bar is of that color is because of the style you have selected. That is a fixed style and uses the system themes for the generation of UI elements.
Look at the source code from here. This progressBarStyleSmall attribute uses the styles defined here.
<style name="Widget.ProgressBar.Small">
<item name="android:indeterminateDrawable">#android:drawable/progress_small_white</item>
<item name="android:minWidth">16dip</item>
<item name="android:maxWidth">16dip</item>
<item name="android:minHeight">16dip</item>
<item name="android:maxHeight">16dip</item>
</style>
Just create a custom style following the example from the android source code. You would need to replace the android:indeterminateDrawable to what you want.
public static void setColorOfProgressBar(ProgressBar mProgressBar, int mColor){
mProgressBar.getIndeterminateDrawable().setColorFilter(mColor, android.graphics.PorterDuff.Mode.MULTIPLY);
}
I had a very hard time trying to change it's color. To solve it, I got android's src code and did my own ProgressBar class.
Not the best answer, but it worked for me.
And the answer was already on SO:
stackoverflow.com/questions/2020882/how-to-change-progress-bars-progress-color-in-android
You can simply change the whole drawable that is shown in the progressbar via the android:indeterminateDrawable attribute.
Just a note, to use
<ProgressBar style="#android:style/Widget.ProgressBar.Inverse"/>
or any of the inverse progress bars, you have to set your minimum android sdk requirement to level 4 (Android 1.6).