Hi guys i have looked at various sites on how to customize the spinner but they have been poor and have not helped me to achieve the look i want. So i have tried to use the rules of customizing a button to help. Here is my code
spinner
<Spinner
android:id="#+id/spinner1"
android:layout_height="30dp"
android:layout_width="300dp"
android:layout_marginLeft="70dp"
android:layout_marginRight="0dp"
android:layout_marginTop="210dp"
android:background="#drawable/scannershape"
android:spinnerMode="dropdown"
/>
background of spinner
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#fafafa"
android:centerColor="#ffffff"
android:endColor="#fafafa"
android:angle="360"/>
<padding android:left="6dp"
android:top="6dp"
android:right="6dp"
android:bottom="6dp" />
<corners android:radius="0dp" />
<stroke android:width="2px" android:color="#cfcfcf" />
</shape>
The look is almost perfect but there are a few things missing.
1,First of all with the normal spinner when it is clicked there is a brief moment when the scanner turns bright orange to show you have clicked it. How do i do this in my customization as it no longer does this anymore in my customized version? and if possible but not important change this color to orange.
2, Secondly the normal spinner has a arrow that points downward to indicate a dropdown list. This is also lost in my customization. How do i customize this arrow into my spinner?
finally were is this file located so i can see if the answers to my question might be there?
android:background="#android:drawable/btn_dropdown"
You may use selector. There's a question for buttons, it's the same for spinner, I think
Related
This is my very first question on StackOverflow, I expect great help from the community :)
I've looked around for this problem's solution for hours but I'm kinda puzzled..
I'm trying to create a custom outlined rounded button for my android app but when I'm applying it through the android:background attribute in XML file, It doesn't quite work. The default background color (purple) is not removed. The stroke is not applied too. However, corners are rounded.
Some say android:background is not working on MaterialButtons. Some say create a style in themes.xml file and reapply it thru android:backgroundTint attribute (It doesn't work either).
Some say try to change it programmatically(not working too!).
Please provide an efficient solution.
Here's my code and what I'm achieving with it.
activity_main
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:background="#drawable/round_button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
round_button
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#color/black" />
<stroke
android:width="3dp"
android:color="#color/teal_200" />
<corners android:radius="25dp" />
</shape>
Here's the result that I get
This is what I want to achieve.
I'm really looking forward to your answers! Thanks.
I faced this before and all I did was change the main theme in the file theme to Appcompat instead of the Material Theme
Hello #Shafique Ahmed,
First of all Welcome to Stack Overflow, and now to answer your question try changing your drawable file as follows and let me know if it works:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item><shape>
<stroke android:width="1dp" android:color="#000000" />
<solid android:color="#android:color/transparent" />
<corners
android:bottomLeftRadius="4dp"
android:bottomRightRadius="4dp"
android:topLeftRadius="4dp"
android:topRightRadius="4dp" />
</shape></item>
</selector>
Edit: You can also change one of your activity's theme from Material Components to App Compact by the following steps:
In the styles.xml(Sometimes also named as themes.xml) make another theme below your main one(New theme: App Compact while keeping the Main theme as Material Components) and give it any name
2.Go the the activity file of the layout you want to change the theme of, and add then call the setTheme(R.style.NameOfTheme); function.
Note: Call the set theme() function before setting the Content View (which is executed by setContentView)
Edit 2: Try refering to
this question to answer your question:
use app:backgroundTint to change your button color
I am trying to create a full width auto complete text field.
So far, I think I have the text field itself looking right. The problem is with the auto complete popup. It has this very bold shadow all around it and I just can't get rid of it.
Don't get me wrong, I still want the shadow, but a subtle shadow, only on the bottom of the popup, not all around it (especially not at the top, that's really weird).
Something like this:
Here's what mine looks like (sorry for giant image):
The Code
activity_main.xml:
<AutoCompleteTextView
android:id="#+id/actvSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginBottom="8dp"
android:background="#drawable/full_width_input"
android:completionThreshold="1"
android:hint="Search a movie..."
android:textColorHint="#BDBDBD"
android:elevation="0dp"
android:popupBackground="#android:color/white" />
full_width_input.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="-1dp" android:right="-1dp" android:left="-1dp">
<shape android:shape="rectangle">
<padding android:bottom="20dp" android:top="20dp" android:left="16dp" android:right="16dp" />
<solid android:color="#android:color/white" />
<stroke android:width="1dp" android:color="#E0E0E0" />
</shape>
</item>
</selector>
use android:popupElevation="0"
<AutoCompleteTextView
android:id="#+id/actvSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginBottom="8dp"
android:background="#drawable/full_width_input"
android:completionThreshold="1"
android:hint="Search a movie..."
android:textColorHint="#BDBDBD"
android:popupElevation="0dp"
android:popupBackground="#android:color/white" />
This question is a bit old already, but anyways. I just crossed through this problem. I was using android:popupBackground="#null" for my autocomplete, but it DOES NOT WORK PROPERLY ON ANDROID 6 (I just tested it).
Instead of using android:popupBackground="#null", use android:popupBackground="#android:color/transparent" (it will also work for the Android 4.4 and 5.0).
If we set android:popupBackground="#null" in AutoCompleteTextView and set background for the adapter row as white, we can achieve this. Hope it will help you.
What I ended up doing is manually creating the auto complete using a ListView.
It took a bit of hacking around but now I have the exact design I had in mind.
I have one spinner in a fragment that have a very annoying graphical glitch.
This occurs only on my Nexus 5 with API 21.
I have try to set spinner.setLayerType(View.LAYER_TYPE_SOFTWARE, null) but the glitch is still present.
Any ideas?
I managed to work around this bug in two different ways:
Set a style to your spinner:
<Spinner
android:background="#drawable/background"
android:id="#+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#android:style/Widget.Holo.Light.Spinner"/>
maybe the background color in the predefined styles is enough for you. If not try
Create a shape drawable with a corner radius:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="2dp" />
<solid android:color="#00ff00" />
</shape>
and set it as a popupBackground to your spinner
<Spinner
android:background="#drawable/spinner_background"
android:id="#+id/date_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:popupBackground="#drawable/spinner_popup_background"/>
hope this is helpful!
I want to create a bar like this initially when progress is zero it will be a fade in color but and as progress goes on it will become bright on that part(This is best I can explain) main thing is i want bar to show all colors at the same time.
Clip your "on" drawable:
over your "off" drawable:
by using res/drawable/custom_progress_drawable.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Background -->
<item
android:id="#android:id/background"
android:drawable="#drawable/custom_progress_bar_off"/>
<!-- Secondary progress - this is optional -->
<item android:id="#android:id/secondaryProgress">
<clip android:drawable="#drawable/custom_progress_bar_secondary" />
</item>
<!-- Progress -->
<item android:id="#android:id/progress">
<clip android:drawable="#drawable/custom_progress_bar_on" />
</item>
</layer-list>
From an Activity, use
Drawable progressDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.custom_progress_drawable, getTheme());
myProgressBar.setProgressDrawable(progressDrawable);
or in xml, use
android:progressDrawable="#drawable/custom_progress_drawable"
And here's the result when using android:max="10" in xml:
It's a little bit off, but you could use setMax() with something more like 10000 and do some offsetting calculations when calling setProgress() to make it cleaner.
Finally! I went on a mission to figure this out for you, so if this suffices, feel free to give me that bounty, haha.
Try using this in your layout:
<View android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight=".20"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:orientation="horizontal"
android:gravity="center"
android:layout_weight="0.62">
<View android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight=".03"/>
<ProgressBar style="?android:attr/progressBarStyleHorizontal"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.94"
android:progressDrawable="#drawable/progressmask"
android:progress="0"
android:max="10"
android:rotation="180"/>
<View android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight=".03"/>
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight=".18"/>
</LinearLayout>
which references this drawable (progressmask.xml):
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<shape>
<corners android:radius="50dip" />
<gradient android:startColor="#00000000" android:endColor="#00000000" android:angle="270" />
<stroke android:width="1dp" android:color="#00000000" />
</shape>
</item>
<item android:id="#android:id/progress">
<clip>
<shape>
<corners android:radius="50dip" />
<gradient android:startColor="#aa000000" android:endColor="#aa000000"
android:angle="270" />
<stroke android:width="1dp" android:color="#00000000" />
</shape>
</clip>
</item>
</layer-list>
and this image (colorprogress.png)
What it does is set the image as the background of a linearlayout, which contains a progressbar. The progressbar adds a semi-transparent black mask to the image to make it appear that the lights are off.
NOTE: In order to get this affect, I had to monkey with the progress bar (i.e. flip it, and set it to only 10 intervals. You will have to do some math to get the progress to line up with the image. i.e. setprogress((100-trueprogress)/10). Sorry I did not do this part for you.
This is what it will look like at progress 50% (the small x's and triangles will disappear on the device)
I hope this answers your question!
Like already suggested i think you should go for an layer-list and set multiple drawables then.
Main problem on this is that i need to be resizeable. An fixed size solution would be quite easy to implement.
You can't actually set the progress bars to different colors. You can however use only the on drawable and get the effect that you want. You could just apply a layer mask. What I mean is add a Relative layout which is initially say dark grey throughout i.e the gradient has only ONE color which is dark gray. Now, use code to set the gradient color on the left programmatically. Obviously the color on the left is going to be transparent. Learn more about Linear Gradients. That's about it. You just need to calculate the position from where the right gradient starts, rather where the left gradient(transparent)ends.
This method is slightly flawed and may not work on ALL devices.
The flawless method would be to create multiple .9png images and set the drawable of the progress dialog programmatically every time.
I'm playing a bit with Android developing some sample applications and came across issue I can't get over with. I'd like to change width of "bar" of SeekBar view.
What I want could be better seen on screenshot provided
http://i.stack.imgur.com/XczAf.png
Could some please be so kind and help me out?
Thanks a lot in advance
You can use thumb drawable for to change hight and and thumb image
Use below line in seekbar xml file
android:thumb="#drawable/seekbar_thumb_draw"
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:thumb="#drawable/seekbar_thumb_draw" />
//seekbar_thumb_draw.xml
<?xml version="1.0" encoding="utf-8"?>
<item>
<shape>
<size
android:height="40dp"
android:width="40dp" />
<solid android:color="#android:color/transparent" />
</shape>
</item>
<item android:drawable="#drawable/seekbar_thumb_image"/>
seekbar_thumb_image is image for thumb that u want
Photshop the exact size that you want. Then save it in your drawables folder. Then reference it in the xml code for your seekbar.
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="wrap_contentt"
android:layout_height="wrap_content"
android:thumb="#drawable/seek_thumb_verywidebar" />