I've been trying various ways to do this through styles but cannot get what I want. It seems I can have a coloured button with a shadow or a button with no shadow for which I can only change the text and pressed colours.
Here's what I have in my styles.xml:
<style name="PrimaryFlatButton" parent="Theme.AppCompat.Light">
<item name="colorControlHighlight">#color/colorPrimary</item>
<item name="colorButtonNormal">#color/colorPrimaryLight</item>
</style>
and here is what I have in my layout:
<Button
android:id="#+id/btn_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/pc_large_padding"
android:theme="#style/PrimaryFlatButton"
style="#style/Widget.AppCompat.Button"
android:text="Search"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
Which gives me a coloured button which darkens when pressed but has a shadow.
If I change the button to have a style of:
style="#style/Widget.AppCompat.Button.Borderless"
Then I successfully lose the shadow but get no background colour unless the button is pressed. I presume Android's idea of "borderless" means having nothing to indicate a border at all - just plain text - rather than making a flat button.
All I want is the standard themed button, with a background colour, which changes colour when pressed, and has no shadow.
You should be able to get a colored button complete with the ripple effect by creating a selector drawable and specifying it as the button's background. Something like this:
some_layout.xml
<Button
style="#style/Theme.Flat.Button"
<!-- Any other properties you want to set -->
/>
style.xml
<style name="Theme.Flat.Button" parent="#style/Widget.AppCompat.Button.Borderless">
<item name="android:background">#drawable/ripple_selector</item>
<!-- Any other items you want to add -->
</style>
ripple_selector.xml
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#color/colorPrimary">
<item>
<selector>
<item android:state_enabled="false">
<color android:color="#color/colorPrimaryLight" />
</item>
<item android:state_enabled="true" android:state_pressed="false">
<color android:color="#color/colorPrimaryLight" />
</item>
<item android:state_enabled="true" android:state_pressed="true">
<color android:color="#color/colorPrimary" />
</item>
</selector>
</item>
</ripple>
You can remove the elevation/shadow by adding android:stateListAnimator="#null" to your button's XML properties.
Full button XML:
<Button
android:id="#+id/btn_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/pc_large_padding"
android:theme="#style/PrimaryFlatButton"
style="#style/Widget.AppCompat.Button"
android:text="Search"
android:stateListAnimator="#null"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
You can also drop this line into your styles.xml in order to avoid adding it to every single one of your buttons
styles.xml:
<style name="PrimaryFlatButton" parent="Theme.AppCompat.Light">
<item name="colorControlHighlight">#color/colorPrimary</item>
<item name="colorButtonNormal">#color/colorPrimaryLight</item>
<item name="android:stateListAnimator">#null</item>
</style>
Michael's answer is also technically correct. If you would like more fine-tuned control over the styling and states of your buttons (including elevation/shadows), you can look into creating your own StateListDrawable resources for your buttons. Since you seem more interested in using the default button styling with only slight modifications, I won't go into further detail about StateListDrawables here. However, if you're interested, you can read Michael's answer as well as the StateListDrawable documentation here.
Related
So I have a listview in my app and it seems that the AppTheme value "colorControlHighlight" changes the colors for ripple and onclick row in that listview to (blue). However I made a listview with identical xml attributes that relate to color on a widget and for some reason the ripple and on press colors are still the default color (white). If I change the android:listselector attribute for the listview on my widget, it works but it doesn't act the same and the ripple effect is gone. How it acts; after I change listselector it stays blue unless I press a different row on the list. This is not what I want (is this because i haven't set onclick actions yet? or is this how that attribute is designed to work?). Any help would be appreciated.
This is my app activity listview
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/AppUrlList"
android:background="#color/dark_black"
android:layout_gravity="center_horizontal"
android:dividerHeight="1px"
android:divider="#color/faded_blue"
android:clickable="true"
/>
now this is my widget listview
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:dividerHeight="2px"
android:divider="#color/faded_blue"
android:background="#color/black"
android:id="#+id/WidgetListView"
android:layout_gravity="center_horizontal" />
now this is my apptheme
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="colorControlNormal">#color/faded_blue</item>
<item name="colorControlActivated">#color/bright_blue</item>
<item name="colorControlHighlight">#color/bright_blue</item>
thanks for the suggestions to improve my question i'm new here
I figured it out i had to do this:
app_list_item.xml
<TextView
android:id="#+id/AppListTextViewGreen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/List_Hint"
android:gravity="center"
android:background="#drawable/list_background_green"
style="#style/liststyleGreen"
/>
then in list_background_green.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="#color/faded_green" />
<item android:state_pressed="true" android:drawable="#color/faded_green"/>
<item android:drawable="#color/black" />
</selector>
the state_pressed is what defines the color when the list item is pressed (obviously)
and the default background is black.
this works on my widget whereas setting the default colors in the app theme did not change the colors in my widget.
EDIT: forgot to put the ripple selector here too, here it is, and i'll also include how to make it work on versions above api 21.
you have to name the ripple selector the same name as the list selector. so you would make another xml named "list_background_green" but put it in drawable-v21 folder. This folder probably won't exist so right click on res folder in android studio and click show in explorer, then create drawable-v21 folder and put the same named xml there. here is an example.
drawable-v21/list_background_green.xml
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#color/bright_green">
<item>
<selector>
<item android:state_selected="true">
<color android:color="#color/transp_green" />
</item>
<item android:state_activated="true">
<color android:color="#color/transp_green" />
</item>
<item android:state_pressed="true">
<color android:color="#color/transp_green" />
</item>
<item>
<color android:color="#color/semi_trans_black" />
</item>
</selector>
</item>
you want to be careful how transparent you make this value.
<color android:color="#color/semi_trans_black" />
i couldn't figure out why the selector wasn't showing up for a while and then realized that if this value is too transparent it makes the ripple not show up. I can't explain why if someone can please do, just warning people because it took me a while to figure out that was the cause. That value is the default background for each textview in the list, so maybe the selectors inherit it's transparency although that doesn't make alot of sense. I only had to do this on my appwidget, for some reason beyond my current understanding. In my regular app listview i didn't need to do any of this. My suspicion is that widgets inherit their theme from the system but i'm not sure of this.
cheers, hope this helps someone.
I'm confused on button styles for material design. I'd like to get colorful raised buttons like in the attached link., like the "force stop" and "uninstall" buttons seen under the usage section. Are there available styles or do I need to define them?
http://www.google.com/design/spec/components/buttons.html#buttons-usage
I couldn't find the default button styles.
Example:
<Button style="#style/PrimaryButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculate"
android:id="#+id/button3"
android:layout_below="#+id/editText5"
android:layout_alignEnd="#+id/editText5"
android:enabled="true" />
If I try to change the background color of the button by adding
android:background="#color/primary"
all of the styles go away, such as the touch animation, shadow, rounded corner, etc.
I will add my answer since I don't use any of the other answers provided.
With the Support Library v7, all the styles are actually already defined and ready to use, for the standard buttons, all of these styles are available:
style="#style/Widget.AppCompat.Button"
style="#style/Widget.AppCompat.Button.Colored"
style="#style/Widget.AppCompat.Button.Borderless"
style="#style/Widget.AppCompat.Button.Borderless.Colored"
Widget.AppCompat.Button:
Widget.AppCompat.Button.Colored:
Widget.AppCompat.Button.Borderless
Widget.AppCompat.Button.Borderless.Colored:
To answer the question, the style to use is therefore
<Button style="#style/Widget.AppCompat.Button.Colored"
.......
.......
.......
android:text="Button"/>
How to change the color
For the whole app:
The color of all the UI controls (not only buttons, but also floating action buttons, checkboxes etc.) is managed by the attribute colorAccent as explained here.
You can modify this style and apply your own color in your theme definition:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
<item name="colorAccent">#color/Orange</item>
</style>
For a specific button:
If you need to change the style of a specific button, you can define a new style, inheriting one of the parent styles described above. In the example below I just changed the background and font colors:
<style name="AppTheme.Button" parent="Widget.AppCompat.Button.Colored">
<item name="colorButtonNormal">#color/Red</item>
<item name="android:textColor">#color/White</item>
</style>
Then you just need to apply this new style on the button with:
android:theme="#style/AppTheme.Button"
To set a default button design in a layout, add this line to the styles.xml theme:
<item name="buttonStyle">#style/btn</item>
where #style/btn is your button theme. This sets the button style for all the buttons in a layout with a specific theme
Simplest Solution
Step 1: Use the latest support library
compile 'com.android.support:appcompat-v7:25.2.0'
Step 2: Use AppCompatActivity as your parent Activity class
public class MainActivity extends AppCompatActivity
Step 3: Use app namespace in your layout XML file
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
Step 4: Use AppCompatButton instead of Button
<android.support.v7.widget.AppCompatButton
android:id="#+id/buttonAwesome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Awesome Button"
android:textColor="#color/whatever_text_color_you_want"
app:backgroundTint="#color/whatever_background_color_you_want"/>
If I understand you correctly, you want to do something like this:
In such case, it should be just enough to use:
<item name="android:colorButtonNormal">#2196f3</item>
Or for API less than 21:
<item name="colorButtonNormal">#2196f3</item>
In addition to Using Material Theme Tutorial.
Animated variant is here.
You can use the
Material Component library.
Add the dependency to your build.gradle:
dependencies { implementation ‘com.google.android.material:material:1.3.0’ }
Then add the MaterialButton to your layout:
<com.google.android.material.button.MaterialButton
style="#style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_name"
app:strokeColor="#color/colorAccent"
app:strokeWidth="6dp"
app:layout_constraintStart_toStartOf="parent"
app:shapeAppearance="#style/MyShapeAppearance"
/>
You can check the full documentation here and API here.
To change the background color you have 2 options.
Using the backgroundTint attribute.
Something like:
<style name="MyButtonStyle"
parent="Widget.MaterialComponents.Button">
<item name="backgroundTint">#color/button_selector</item>
//..
</style>
It will be the best option in my opinion. If you want to override some theme attributes from a default style then you can use new materialThemeOverlay attribute.
Something like:
<style name="MyButtonStyle"
parent="Widget.MaterialComponents.Button">
<item name=“materialThemeOverlay”>#style/GreenButtonThemeOverlay</item>
</style>
<style name="GreenButtonThemeOverlay">
<!-- For filled buttons, your theme's colorPrimary provides the default background color of the component -->
<item name="colorPrimary">#color/green</item>
</style>
The option#2 requires at least the version 1.1.0.
You can use one of these styles:
Filled Button (default): style="#style/Widget.MaterialComponents.Button
Text Button: style="#style/Widget.MaterialComponents.Button.TextButton"
OutlinedButton: style="#style/Widget.MaterialComponents.Button.OutlinedButton"
OLD Support Library:
With the new Support Library 28.0.0, the Design Library now contains the MaterialButton.
You can add this button to our layout file with:
<android.support.design.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="YOUR TEXT"
android:textSize="18sp"
app:icon="#drawable/ic_android_white_24dp" />
By default this class will use the accent colour of your theme for the buttons filled background colour along with white for the buttons text colour.
You can customize the button with these attributes:
app:rippleColor: The colour to be used for the button ripple effect
app:backgroundTint: Used to apply a tint to the background of the button. If you wish to change the background color of the button, use this attribute instead of background.
app:strokeColor: The color to be used for the button stroke
app:strokeWidth: The width to be used for the button stroke
app:cornerRadius: Used to define the radius used for the corners of the button
Here is how I got what I wanted.
First, made a button (in styles.xml):
<style name="Button">
<item name="android:textColor">#color/white</item>
<item name="android:padding">0dp</item>
<item name="android:minWidth">88dp</item>
<item name="android:minHeight">36dp</item>
<item name="android:layout_margin">3dp</item>
<item name="android:elevation">1dp</item>
<item name="android:translationZ">1dp</item>
<item name="android:background">#drawable/primary_round</item>
</style>
The ripple and background for the button, as a drawable primary_round.xml:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#color/primary_600">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="1dp" />
<solid android:color="#color/primary" />
</shape>
</item>
</ripple>
This added the ripple effect I was looking for.
Beside android.support.design.button.MaterialButton (which mentioned by Gabriele Mariotti),
There is also another Button widget called com.google.android.material.button.MaterialButton which has different styles and extends from AppCompatButton:
style="#style/Widget.MaterialComponents.Button"
style="#style/Widget.MaterialComponents.Button.UnelevatedButton"
style="#style/Widget.MaterialComponents.Button.TextButton"
style="#style/Widget.MaterialComponents.Button.Icon"
style="#style/Widget.MaterialComponents.Button.TextButton.Icon"
Filled, elevated Button (default):
style="#style/Widget.MaterialComponents.Button"
Filled, unelevated Button:
style="#style/Widget.MaterialComponents.Button.UnelevatedButton"
Text Button:
style="#style/Widget.MaterialComponents.Button.TextButton"
Icon Button:
style="#style/Widget.MaterialComponents.Button.Icon"
app:icon="#drawable/icon_24px" // Icons can be added from this
A text Button with an icon::
Read: https://material.io/develop/android/components/material-button/
A convenience class for creating a new Material button.
This class supplies updated Material styles for the button in the
constructor. The widget will display the correct default Material
styles without the use of the style flag.
Here is a sample that will help in applying button style consistently across your app.
Here is a sample Theme I used with the specific styles..
<style name="MyTheme" parent="#style/Theme.AppCompat.Light">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/accent</item>
<item name="android:buttonStyle">#style/ButtonAppTheme</item>
</style>
<style name="ButtonAppTheme" parent="android:Widget.Material.Button">
<item name="android:background">#drawable/material_button</item>
</style>
This is how I defined the button shape & effects inside res/drawable-v21 folder...
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?attr/colorControlHighlight">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="2dp" />
<solid android:color="#color/primary" />
</shape>
</item>
</ripple>
2dp corners are to keep it consistent with Material theme.
I tried a lot of answer & third party libs, but none was keeping the border and raised effect on pre-lollipop while having the ripple effect on lollipop without drawback. Here is my final solution combining several answers (border/raised are not well rendered on gifs due to grayscale color depth) :
Lollipop
Pre-lollipop
build.gradle
compile 'com.android.support:cardview-v7:23.1.1'
layout.xml
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card"
card_view:cardElevation="2dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardMaxElevation="8dp"
android:layout_margin="6dp"
>
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:background="#drawable/btn_bg"
android:text="My button"/>
</android.support.v7.widget.CardView>
drawable-v21/btn_bg.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="?attr/colorPrimary"/>
</ripple>
drawable/btn_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/colorPrimaryDark" android:state_pressed="true"/>
<item android:drawable="#color/colorPrimaryDark" android:state_focused="true"/>
<item android:drawable="#color/colorPrimary"/>
</selector>
Activity's onCreate
final CardView cardView = (CardView) findViewById(R.id.card);
final Button button = (Button) findViewById(R.id.button);
button.setOnTouchListener(new View.OnTouchListener() {
ObjectAnimator o1 = ObjectAnimator.ofFloat(cardView, "cardElevation", 2, 8)
.setDuration
(80);
ObjectAnimator o2 = ObjectAnimator.ofFloat(cardView, "cardElevation", 8, 2)
.setDuration
(80);
#Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
o1.start();
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
o2.start();
break;
}
return false;
}
});
1) You can create rounded corner button by defining xml drawable and you can increase or decrease radius to increase or decrease roundness of button corner.
Set this xml drawable as background of button.
<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="4dp"
android:insetTop="6dp"
android:insetRight="4dp"
android:insetBottom="6dp">
<ripple android:color="?attr/colorControlHighlight">
<item>
<shape android:shape="rectangle"
android:tint="#0091ea">
<corners android:radius="10dp" />
<solid android:color="#1a237e" />
<padding android:bottom="6dp" />
</shape>
</item>
</ripple>
</inset>
2) To change default shadow and shadow transition animation between button states, you need to define selector and apply it to button using android:stateListAnimator property. For complete button customization reference : http://www.zoftino.com/android-button
I've just created an android library, that allows you to easily modify the button color and the ripple color
https://github.com/xgc1986/RippleButton
<com.xgc1986.ripplebutton.widget.RippleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btn"
android:text="Android button modified in layout"
android:textColor="#android:color/white"
app:buttonColor="#android:color/black"
app:rippleColor="#android:color/white"/>
You don't need to create an style for every button you want wit a different color, allowing you to customize the colors randomly
// here is the custom button style
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:angle="45"
android:centerColor="#color/colorPrimary"
android:startColor="#color/colorPrimaryDark"
android:endColor="#color/colorAccent"
>
</gradient>
<corners
android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
>
</corners>
<stroke
android:width="2dp"
android:color="#color/colorWhite"
>
</stroke>
</shape>
</item>
</selector>
you can give aviation to the view by adding z axis to it and can have default shadow to it. this feature was provided in L preview and will be available after it release. For now you can simply add a image the gives this look for button background
I would like to change the blue colour below the edit text, i don't know what property it is.
I tried using a different background colour for it but it didn't work.
I've attached an image below:
It's actually fairly easy to set the underline color of an EditText programmatically (just one line of code).
To set the color:
editText.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_IN);
To remove the color:
editText.getBackground().clearColorFilter();
Note: when the EditText has focus on, the color you set won't take effect, instead, it has a focus color.
API Reference:
Drawable#setColorFilter
Drawable#clearColorFilter
Use android:backgroundTint="" in your EditText xml layout.
For api<21 you can use AppCompatEditText from support library thenapp:backgroundTint=""
You have to use a different background image, not color, for each state of the EditText (focus, enabled, activated).
http://android-holo-colors.com/
In the site above, you can get images from a lot of components in the Holo theme. Just select "EditText" and the color you want. You can see a preview at the bottom of the page.
Download the .zip file, and copy paste the resources in your project (images and the XML).
if your XML is named: apptheme_edit_text_holo_light.xml (or something similar):
Go to your XML "styles.xml" and add the custom EditText style:
<style name="EditTextCustomHolo" parent="android:Widget.EditText">
<item name="android:background">#drawable/apptheme_edit_text_holo_light</item>
<item name="android:textColor">#ffffff</item>
</style>
Just do this in your EditText:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/EditTextCustomHolo"/>
And that's it, I hope it helps you.
This works fine for old and new version of Android (works fine even on API 10!).
Define this style in your styles.xml:
<style name="EditText.Login" parent="Widget.AppCompat.EditText">
<item name="android:textColor">#android:color/white</item>
<item name="android:textColorHint">#android:color/darker_gray</item>
<item name="colorAccent">#color/blue</item>
<item name="colorControlNormal">#color/blue</item>
<item name="colorControlActivated">#color/blue</item>
</style>
And now in your XML, set this as theme and style (style to set textColor, and theme to set all other things):
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
style="#style/EditText.Login"
android:theme="#style/EditText.Login"/>
Edit
This solution causes a tiny UI glitch on newer Android versions (Lollipop or Marshmallow onwards) that the selection handles are underlined.
This issue is discussed in this thread. (I haven't tried this solution personally)
you can change Underline of EditText color specifying it in styles.xml. In your app theme styles.xml add the following.
<item name="android:textColorSecondary">#color/primary_text_color</item>
As pointed out by ana in comment section
<item name="android:colorControlActivated">#color/black</item>
setting this in theme style works well for changing color of an edittext underline.
So, you need to create a new .xml file in your drawable folder.
In that file paste this code:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="8dp"
android:left="-3dp"
android:right="-3dp"
android:top="-3dp">
<shape android:shape="rectangle">
<stroke
android:width="1dp"
android:color="#color/white"/>
</shape>
</item>
</layer-list>
And in your EditText, set
android:background="#drawable/your_drawable"
You can play with your drawable xml, set corners, paddings, etc.
In your app style define the property colorAccent. Here you find an example
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/action_bar</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/action_bar</item>
</style>
You can change the color of EditText programmatically just using this line of code easily:
edittext.setBackgroundTintList(ColorStateList.valueOf(yourcolor));
To change bottom line color, you can use this in your app theme:
<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="colorControlNormal">#c5c5c5</item>
<item name="colorControlActivated">#ffe100</item>
<item name="colorControlHighlight">#ffe100</item>
</style>
To change floating label color write following theme:
<style name="TextAppearence.App.TextInputLayout" parent="#android:style/TextAppearance">
<item name="android:textColor">#4ffd04[![enter image description here][1]][1]</item>
</style>
and use this theme in your layout:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
app:hintTextAppearance="#style/TextAppearence.App.TextInputLayout">
<EditText
android:id="#+id/edtTxtFirstName_CompleteProfileOneActivity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:capitalize="characters"
android:hint="User Name"
android:imeOptions="actionNext"
android:inputType="text"
android:singleLine="true"
android:textColor="#android:color/white" />
</android.support.design.widget.TextInputLayout>
Use below code to change background color of edit-text's border.
Create new XML file under drawable.
abc.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#00000000" />
<stroke android:width="1dip" android:color="#ffffff" />
</shape>
and add it as background of your edit-text
android:background="#drawable/abc"
If you don't have to support devices with API < 21, use backgroundHint in xml, for example:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:hint="Task Name"
android:ems="10"
android:id="#+id/task_name"
android:layout_marginBottom="15dp"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textColorLink="#color/blue"
android:textColorHint="#color/blue"
android:backgroundTint="#color/lighter_blue" />
For better support and fallbacks use #Akariuz solution.
backgroundHint is the most painless solution, but not backward compatible, based on your requirements make a call.
change your colorAccent which color you need that color set on colorAccent and run you get the output
Simply change android:backgroundTint in xml code to your color
You can do it with AppCompatEditText and color selector:
<androidx.appcompat.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:backgroundTint="#color/selector_edittext_underline" />
selector_edittext_underline.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/focused_color"
android:state_focused="true" />
<item android:color="#color/hint_color" />
</selector>
NOTE: Put this selector file in res/color folder, not res/drawable. ususually res/color does not exist and we may have to create it.
This is a pretty specific question. I have a spinner on an ActionBar that is added in the onCreate() method. I have been able to style the text white, but I can't get the underline and the triangle/arrow at the bottom right to appear as white. Here is my styling:
<item name="android:actionDropDownStyle">#style/customActionBarDropDownStyle</item>
<style name="customActionBarDropDownStyle" parent="android:style/Widget.Holo.Light.Spinner">
<item name="android:textColor">#FFFFFF</item>
</style>
I can't find a style item/property that makes the underline and triangle white. Does one exists?
Here's an example. I have highlighted in red the triangle and underline that I want to make white.
A bit late answer, but better than never :)
You should create a new 9 patch drawable and set it as a background to android:actionDropDownStyle.
here is an example:
<item name="android:actionDropDownStyle">#style/customActionBarDropDownStyle</item>
<style name="customActionBarDropDownStyle"parent="android:style/Widget.Holo.Light.Spinner">
<item name="android:background">#drawable/custom_spinner_dropdown</item>
</style>
You can't set a color to almost every native component, as their backgrounds are (in most cases) 9-patch pngs.
The actionDropDownStyle can not used to change the style of spinner you added on actionbar; its for one of the actionbar mode ActionBar.NAVIGATION_MODE_LIST;
As for your problem, you can define a selector for your spinner in the layout file,just like this:
enter code here
<Spinner
android:dropDownWidth="200dp"
android:background="#drawable/actionbar_spinner"
android:id="#+id/action_spinner"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="10dp" />
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false"
android:drawable="#drawable/spinner_ab_disabled" />
<item android:state_pressed="true"
android:drawable="#drawable/spinner_ab_pressed" />
<item android:state_pressed="false" android:state_focused="true"
android:drawable="#drawable/spinner_ab_focused" />
<item android:drawable="#drawable/spinner_ab_default" />
</selector>
Try this : android:background="#null"
I have a button. When I press the button I have to make text as bold otherwise normal. So I wrote styles for bold & normal.
<style name="textbold" parent="#android:style/TextAppearance">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textStyle">bold</item>
</style>
<style name="textregular" parent="#android:style/TextAppearance">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textStyle">normal</item>
</style>
Now I have a button_states.xml as:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="true"
style="#style/textbold" />
<item android:state_focused="false" android:state_pressed="true"
style="#style/textregular" />
<item style="#style/textregular" />
</selector>
In my layout for this button, I have to make the background as transparent too...How will I do it? My layout code is :
<Button android:id="#+id/Btn" android:background="#drawable/button_states" />
How will I include background as transparent in my style?
To make a background transparent, just do android:background="#android:color/transparent".
However, your problem seems to be a bit deeper, as you're using selectors in a really weird way. The way you're using it seems wrong, although if it actually works, you should be putting the background image in the style as an <item/>.
Take a closer look at how styles are used in the Android source. While they don't change the text styling upon clicking buttons, there are a lot of good ideas on how to accomplish your goals there.
Try new way to set background transparent
android:background="?android:attr/selectableItemBackground"
You may also use:
in your xml:
android:background="#null"
or in code:
buttonVariable.setBackgroundColor(Color.TRANSPARENT);
use #0000 (only four zeros otherwise it will be considered as black) this is the color code for transparent. You can use it directly but I recommend you to define a color in color.xml so you can enjoy re-usefullness of the code.
Add this in your Xml - android:background="#android:color/transparent"
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Button"
android:background="#android:color/transparent"
android:textStyle="bold"/>
I achieved this with in XML with
android:background="#android:color/transparent"
I used
btn.setBackgroundColor(Color.TRANSPARENT);
and
android:background="#android:color/transparent"
Selectors work only for drawables, not styles. Reference
First, to make the button background transparent use the following attribute as this will not affect the material design animations:
style="?attr/buttonBarButtonStyle"
There are many ways to style your button. Check out this tutorial.
Second, to make the text bold on pressed, use this java code:
btn.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
// When the user clicks the Button
case MotionEvent.ACTION_DOWN:
btn.setTypeface(Typeface.DEFAULT_BOLD);
break;
// When the user releases the Button
case MotionEvent.ACTION_UP:
btn.setTypeface(Typeface.DEFAULT);
break;
}
return false;
}
});
We can use attribute android:background in Button xml like below.
android:background="?android:attr/selectableItemBackground"
Or we can use style
style="?android:attr/borderlessButtonStyle" for transparent and shadow less background.
You can achieve that by setting the colors alpha channel.
The color scheme is like this #AARRGGBB there A stands for alpha channel(transparency), R stands for red, G for green and B for blue.
Step 1:
Create a new resource file in drawable and copy paste
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:color="#fff" android:width="2dp"/>
<corners android:radius="25dp"/>
<padding android:right="15dp" android:top="15dp" android:bottom="15dp" android:left="15dp"/>
</shape>
save it as ButtonUI(let's say)
Step 2: Apply the UI to the button xml
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="join the crew"
android:background="#drawable/ButtonUI"
android:textColor="#fff"/>
I'd say extend Borderless style.
<style name="Button" parent="Widget.AppCompat.Button.Borderless">
<item name="android:textColor">#color/blue</item>
<item name="android:textAllCaps">true</item>
</style>
Code:
button.setVisibility(View.INVISIBLE);
Xml:
android:background="#android:color/transparent"
You can do it easily by adding below attribute in xml file. This code was tested plenty of time.
android:background="#android:color/transparent"
You apply the background color as transparent(light gray) when you click the button.
ButtonName.setOnClickListener()
In the above method you set the background color of the button.