I need to add an underline below my Spinner. From these links:
Android Spinner Underline color
I want to underline spinner (android)
I have implemented the below:
In reminder_dialog_fragment.xml
<android.support.v7.widget.AppCompatSpinner
android:id="#+id/spinner_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/Widget.AppCompat.Spinner.Underlined"
android:theme="#style/MySpinnerTheme" />
In styles.xml
<style name="MySpinnerTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- set color for underline below Spinner -->
<item name="colorControlActivated">#ffcfd8dc</item>
<item name="colorControlHighlight">#ffcfd8dc</item>
<item name="colorControlNormal">#ffcfd8dc</item>
</style>
I managed to display underline below Spinner & change the underline's color. But during spinner onclick / highlighted, there is some animation effect on Spinner:
Ripple effect on the triangle (right side of Spinner)
The underline below Spinner become bold
How can I remain the effect of (1), but disable the effect of (2)?
In other words, I want to prevent the underline become bold when Spinner is clicked.
may be you can try
android:elevation="5dp"
in xml
Try to use below code snippet for removing Spinner Bottomline color
app:ms_basecolor="#android:color/transparent"
app:ms_hightlightcolor="#android:color/transparent"
I hope it will work for you!
There are multiple ways to do it. Try to give background as transparent.
<Spinner
android:id="#+id/spTest"
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:prompt="#string/spinner_prompt"
android:background="#android:color/transparent"
android:entries="#array/spinnerList"/>
Or create an EditText as shown in the code below:
<EditText
android:id="#+id/etTest"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:layout_margin="10dp"
android:background="#drawable/edittext_rectangale_border"
android:drawableEnd="#drawable/ic_arrow_drop"
android:focusable="false"
android:focusableInTouchMode="false"
android:hint="#string/spinner_prompt"
android:inputType="text"
android:padding="5dp" />
You can find the drop_down_arrow from the vector asset. For the Border of EditText create a drawable named "edittext_rectangle_border.xml" and paste the below code in it.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<stroke
android:width="3dp"
android:color="#B9B9B9"/>
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp"/>
<corners
android:bottomLeftRadius="3dp"
android:bottomRightRadius="3dp"
android:topLeftRadius="3dp"
android:topRightRadius="3dp"/>
</shape>
After completing the above things, Open the java file and create a Dialog on EditText click by using onSetClickListner and display the list in the dialogbox. Later on selection of item set the EditText text.
Hope you find it useful.
Related
I am using TextInputLayout around edittext. I want to change the border color of the edit text which is present inside the TextInputLayout.
xml
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="#+id/Test1"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.TextInputLayout>
Csharp
private TextInputEditText editor;
editor = FindViewById<TextInputEditText>(Resource.Id.Test6);
editor.Background.SetColorFilter(Android.Graphics.Color.Red, Android.Graphics.PorterDuff.Mode.SrcAtop);
This above code works correctly, if the edit text is not present inside the TextInputLayout. Only gets problem while using the edittext inside the TextInputLayout. How can I fix this?
create drawable file in drawable folder i.e.
drawable_name.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Background Color -->
<solid android:color="#ffffff" />
<!-- Border Color -->
<stroke android:width="1dp" android:color="#e7e7e7e7" />
<!-- Round Corners -->
<corners android:radius="5dp" />
</shape>
and set this drawable to edittext
drawble = "#drawable/drawble_name"
change color of border as per your requirement
put the style in your style,
<style name="LoginTextInputLayoutStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
<item name="boxStrokeColor">#fff</item>
<item name="boxStrokeWidth">2dp</item>
</style>
and add the following color to your color.xml
<color name="mtrl_textinput_default_box_stroke_color" tools:override="true">#fff</color>
Change the TextInputLayout outline color
I have successfully designed a dialog spinner as shown below. Now what I want is to set the background color of the spinner to be transparent and add the divider between the items.
What I have done is adding a "Spinner Style" style of the spinner in styles.xml with android:divider, android:height divider and android:padding attributes, and then add the style attribute to the Spinner, however, the result is no different.
On the other hand, I have tried to merely change the color of the spinner pop up a background to be transparent, however, this result is not my desired one.
Hence, I hope to see any advice and documents to solve this problem! Thanks for all help!
my current spinner pop up and what I want could look like desired result(the autocomplete view is irrelevant; I just care about the background and divider between the items)
**customize_spinner_shape_in_search_frame.xml**
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
style="#style/spinnerStyle">
<!-- view background color -->
<solid
android:color="#EFB1B9" >
</solid>
<corners
android:radius="20dp" >
</corners>
</shape>
**Spinner in layout.xml**
<Spinner
android:id="#+id/search_criteria_activity_spn_subject_title"
android:layout_width="188dp"
android:layout_height="51dp"
android:layout_marginStart="8dp"
android:layout_marginTop="36dp"
android:spinnerMode="dialog"
android:backgroundTintMode="add"
android:background="#drawable/customize_spinner_shape_in_search_frame"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/search_criteria_activity_s2"
style="#style/spinnerStyle"/>
**And lastly, the SpinnerStyle in styles.xml:**
<style name="spinnerStyle" parent="Widget.AppCompat.Spinner">
<item name="android:divider">#d1d1d1</item>
<item name="android:dividerHeight">0.5dp</item>
<item name="android:padding">5sp</item>
</style>
You can use android:popupBackground="#android:color/transparent" to change Popup background to transparent
<Spinner
android:id="#+id/search_criteria_activity_spn_subject_title"
android:layout_width="188dp"
android:layout_height="51dp"
android:layout_marginStart="8dp"
android:layout_marginTop="36dp"
android:spinnerMode="dialog"
android:backgroundTintMode="add"
android:background="#drawable/customize_spinner_shape_in_search_frame"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/search_criteria_activity_s2"
style="#style/spinnerStyle"
android:popupBackground="#android:color/transparent"/>
How to put underbar in edit text , previously underbar comes automatically but now i cannot find it now . I have to add it using android : background attribute and make a line shape in drawable , but this also dont work as the stroke appears in the centre of the texts . So how can i get that under bar
Edit text code
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/line2"
android:hint="hhkfnvkslnbkfnbkfnbknbdkbnlbkn"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:textColorHint="#color/colorAccent" />
Stroke
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line">
<stroke android:width="1dp" android:color="#0000FF"/>
<size android:height="100dp" />
</shape>
Just create a view below the EditText:
<EditText
android:id="#+id/underbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/line2"
android:hint="hhkfnvkslnbkfnbkfnbknbdkbnlbkn"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:textColorHint="#color/colorAccent" />
<View
android:id="#+id/underbar"
style="#style/EditTextLine"
android:layout_below="#+id/underbar"/>
And in your styles.xml,
<style name="EditTextLine">
<item name="android:layout_height">1dp</item>
<item name="android:layout_width">match_parent</item>
<item name="android:background">#color/colorAccent</item>
</style>
Make sure that the EditText and the View is wrapped in a RelativeLayout. You can re-use the same underbar-style below every EditText.
In my Android app I have button with arrow image on the right side. On my SettingsActivity you can change the color of app (change the color of buttons and TextViews).
I changed the color of TextViews fine, but when I changed the color of buttons, the image (arrow on the right side) is gone.
Thats my code now. It change color and delete the imge.
loginButton = (Button) findViewById(R.id.btnLogin);
loginButton.setTextColor(color);
I find this on some post. But this only works for ImgageView, not for button.
loginButton = (Button) findViewById(R.id.btnLogin);
GradientDrawable bgShape = (GradientDrawable)loginButton.getBackground();
bgShape.setColor(getResources().getColor(Color.BLACK));
text.setTextColor(color);
I also tryed to change the color like this. But this does not change the color at all.
Drawable button = context.getResources().getDrawable(R.drawable.button);
button.setColorFilter(new
PorterDuffColorFilter(0xffff00,Mode.MULTIPLY));
The last thing which I hope should work is to define new drawable for every color. But this is really awful...
I also think, that the problem is not only with the image. I think this solution overrides all the drawable file...
Is there anyone who knows how to change the color of drawable and keep the image on the button?
EDIT: Just trying... I can move all colors to colors.xml file. And change the path of color to all drawable files. Like
<resource>
Color 1
Color 2
Color 3
...
</resource>
But than how can drawable files decide which color it should use?
EDIT2: Button layout:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
style="#style/bgGrey">
<RelativeLayout
android:layout_height="0dip"
android:layout_weight="30"
android:layout_width="fill_parent"
>
<TextView
...
/>
</RelativeLayout>
<LinearLayout
...>
<TextView
.../>
<EditText
.../>
<TextView
.../>
<EditText
.../>
<Button
android:id="#+id/btnLogin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/password"
android:gravity="center|left"
android:paddingLeft="15dp"
android:layout_marginTop="10dp"
android:background="#drawable/login_button_background"
android:text="Login" />
</LinearLayout>
</LinearLayout>
Button drawable, background.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/layer"></item>
</selector>
layer.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:left="0dp" android:top="5dp" android:bottom="5dp" android:right="0dp" >
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#ffb500"/>
</shape>
</item>
<item android:left="350dp" android:top="5dp" android:bottom="5dp" android:right="5dp" >
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#ffb500"/>
</shape>
</item>
<item android:right="15dp" >
<bitmap android:src="#drawable/btn_right" android:gravity="right" android:tileMode="disabled" />
</item>
</layer-list>
An alternative approach can be: Remove the arrow from the background and set it as Compound Drawable.
As Button extends TextView, you can set drawables to the top, bottom, left or right.
In the XML, just set the property drawableRight to an arrow, or via JAVA code:
button.setCompoundDrawablesWithIntrinsicBounds (idLeft, idTop, idRight, idBottom)
So to set a right arrow:
button.setCompoundDrawablesWithIntrinsicBounds (0, 0, R.drawable.your_arrow, 0);
This way, the background is independent from the arrow, and it will be easier to modify it without creating complex versions or selectors.
There are methods and properties to adjust the drawable padding so you can place it more or less where you need it.
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