android spinner dialog popup background - android

My android app already set popupbackground as drawable xml. However, the popup dialog still cannot show the color I set. How to settle this issue?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".CountrySelectorActivity">
<Spinner
android:id="#+id/search_spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#color/black"
android:popupBackground="#drawable/spinner_background"
android:spinnerMode="dialog"
/>
<Spinner
android:id="#+id/search_spinner2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:background="#color/black"
android:popupBackground="#drawable/spinner_background"
android:spinnerMode="dialog"/>
</LinearLayout>
#drawable/spinner_background.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#color/green"/>
</shape>
</item>
</selector>
Spinner activity code
https://stackoverflow.com/questions/51495271/android-kotlin-spinner-working-for-api-23-but-not-working-for-api-21

Make a style using your custom spinner background drawable. Then add the style as an attribute to your spinner. Lastly, programmatically change the spinner popup background color in your activity or fragment. The following way worked for me:
<style name="SpinnerTheme" parent="android:Widget.DeviceDefault.Spinner">
<item name="android:background">#drawable/spinner_background</item>
<item name="android:padding">8dp</item>
<item name="android:paddingTop">5dp</item>
<item name="android:textSize">18sp</item>
<item name="android:textColor">#android:color/white</item>
<item name="android:paddingBottom">5dp</item>
<item name="android:paddingRight">15dp</item>
</style>
Put this in your xml for each spinner (REMOVE android:popupBackground="#drawable/spinner_background" &
android:spinnerMode="dialog"):
<Spinner
android:id="#+id/search_spinner2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:background="#color/black"
style="#style/SpinnerTheme"/>
Then in your activity or fragment, programmatically set the popup background color:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
spinner.setPopupBackgroundResource(R.color.yourColor);
}
Here is a link to example: https://www.oodlestechnologies.com/blogs/Custom-Spinner-In-Android

With AndroidX and using AppCompatSpinner you can do this:
File: styles.xml
<style name="MyPopUpTheme">
<item name="android:background">#color/background_spinner</item>
<item name="android:padding">5dp</item>
<item name="android:textColor">#color/colorAccent</item>
<item name="android:textStyle">bold</item>
</style>
File: Your fragment or Activity
<androidx.appcompat.widget.AppCompatSpinner
android:id="#+id/spinner_years"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="50dp"
android:background="#drawable/spinner_bg"
android:padding="15dp"
android:theme="#style/MyPopUpTheme" />
Result:

Related

How to change button background in Android in Neumorphism design concept?

I am working in Neumorphism based designs in my project. I am using this library https://github.com/fornewid/neumorphism for Neumorphism effect. My issue is I can't able to change the background of the button or any other views.
This is my layout file
activity_neumorphism.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/screen_background_gradient"
tools:context=".NeumorphismActivity">
<soup.neumorphism.NeumorphButton
android:id="#+id/button"
style="#style/Widget.Neumorph.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="36dp"
android:drawablePadding="8dp"
android:background="#drawable/res_transparent_yellow_roundedfilled_corner"
android:text="Button"
android:textColor="#FFFFFF"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="#+id/normal_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button"
android:layout_marginTop="50dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="#drawable/res_transparent_yellow_roundedfilled_corner"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#+id/normal_button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:text="THIS IS NORMAL BUTTON"
android:textColor="#FFFFFF"
android:layout_marginTop="30dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#+id/button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:text="THIS IS Neumorphism effect BUTTON"
android:textColor="#FFFFFF"
android:layout_marginTop="30dp"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
I have two buttons in this xml. One is normal button and another is neumorphism. I have set background for both but it's only applies for normal button.
Below given is drawable file for background
res_transparent_yellow_roundedfilled_corner.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:shape="rectangle">
<corners
android:radius="10dp"
/>
<gradient
android:startColor="#C8A800"
android:endColor="#FFD80A"/>
</shape>
Below given is styles.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Widget.Neumorph.Button" parent="Widget.AppCompat.Button">
<item name="android:textAppearance">?android:attr/textAppearanceButton</item>
<item name="android:minHeight">72dip</item>
<item name="android:minWidth">112dip</item>
<item name="android:background">#drawable/res_transparent_yellow_roundedfilled_corner</item>
<item name="android:paddingLeft">#dimen/design_btn_padding_left</item>
<item name="android:paddingRight">#dimen/design_btn_padding_right</item>
<item name="android:paddingTop">#dimen/design_btn_padding_top</item>
<item name="android:paddingBottom">#dimen/design_btn_padding_bottom</item>
<item name="android:stateListAnimator">#animator/button_state_list_anim_neumorph</item>
<item name="android:focusable">true</item>
<item name="android:clickable">true</item>
<item name="android:gravity">center_vertical|center_horizontal</item>
<item name="neumorph_inset">#dimen/design_default_inset</item>
<item name="neumorph_shadowElevation">6dp</item>
<item name="neumorph_shadowColorLight">#FFFFFF</item>
<item name="neumorph_shadowColorDark">#000000</item>
<item name="neumorph_shapeType">flat</item>
<item name="neumorph_shapeAppearance">#style/ShapeAppearance.Neumorph.Button</item>
</style>
<style name="ShapeAppearance.Neumorph.Button" parent="">
<item name="background"> #drawable/res_transparent_yellow_roundedfilled_corner</item>
</style>
</resources>
use this property to change background app:neumorph_backgroundColor="#color/background_color" in your xml
if not working, there is one method inside NeumorphButton is setBackgroundDrawable. you can set drawable programmatically
Edit
you can't set the custom background in this lib because it says
Setting a custom background is not supported.

How to set underline color of TextInputLayout [duplicate]

This question already has an answer here:
TextInputLayout styling
(1 answer)
Closed 2 years ago.
I'm using com.google.android.material:material:1.1.0 on Android 9.0.
I want to set the underline color of TextInputLayout when it's not focused but nothing works.
My style:
<style name="EditTextTheme" parent="Widget.MaterialComponents.TextInputLayout.FilledBox">
<item name="colorAccent">#00BFFF</item>
<item name="colorControlNormal">#FFFF00</item>
<item name="colorControlActivated">#FF00FF</item>
<item name="colorControlHighlight">#FFFF00</item>
<item name="boxStrokeColor">#color/text_input_box_stroke</item>
</style>
My selector(text_input_box_stroke):
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#00BFFF" android:state_focused="true"/>
<item android:color="#FFFF00" android:state_hovered="true"/>
<item android:color="#00FF00" android:state_enabled="false"/>
</selector>
And my TextInputLayout:
<com.google.android.material.textfield.TextInputLayout
style="#style/EditTextTheme"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:hint="Email">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textWebEmailAddress" />
</com.google.android.material.textfield.TextInputLayout>
right-click res -> new -> Android Resource Directory -> Resource type -> color
name your file for example text_input_box_stroke.xml and put it in color folder
text_input_box_stroke.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_enabled="true"
android:color="#00BFFF" />
<item
android:state_pressed="true"
android:color="#FFFF00" />
<item
android:state_focused="true"
android:color="#00C853" />
<item
android:color="#ff00ff" />
</selector>
to prevent TextInputLayout view from gaining focus when activity or fragment which contains it start put this attributes to the parent layout which contains TextInputLayout
android:fadeScrollbars="false"
android:fillViewport="true"
layout file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
android:focusable="true"
android:focusableInTouchMode="true"
android:id="#+id/content">
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/layout_data"
style="#style/TextInputLayoutStyleFilledBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="Hint"
android:textColorHint="#color/black"
app:boxBackgroundColor="#android:color/transparent"
app:boxStrokeWidth="2dp"
app:hintTextColor="#color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/input_value"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="123456789" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
styles.xml
<style name="TextInputLayoutStyleFilledBox"
parent="#style/Widget.MaterialComponents.TextInputLayout.FilledBox">
<item name="colorAccent">#00BFFF</item>
<item name="colorControlNormal">#FFFF00</item>
<item name="colorControlActivated">#FF00FF</item>
<item name="colorControlHighlight">#FFFF00</item>
<item name="boxStrokeColor">#color/text_input_box_stroke</item>
</style>

Android Studio ImageButton changing shape after implementing a style

I've searched here and it doesn't seem like anyone has had this problem.
I'm following the Android Studio tutorials from here.
Basically what is happening is that my buttons look fine when I implement my XML code, but when I transfer over some of the XML code to my styles.xml and import it into my activity_main.xml file, my button changes its dimensions.
Here's my activity_main.xml file.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16sp"
tools:context=".MainActivity"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageButton
android:id="#+id/decreaseTeam1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_minus"
android:contentDescription="#string/minus_button"
android:background="#drawable/button_background"
android:onClick="decreaseScore" />
<ImageButton
android:id="#+id/increaseTeam1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_plus"
android:contentDescription="#string/plus_button"
android:layout_alignParentEnd="true"
android:onClick="increaseScore"
android:background="#drawable/button_background"/>
<TextView
android:id="#+id/score_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:text="#string/initial_score"/>
<TextView
android:id="#+id/team1_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="#string/team_1"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageButton
android:id="#+id/decreaseTeam2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_minus"
android:background="#drawable/button_background"
android:contentDescription="#string/minus_button"
android:onClick="decreaseScore"
/>
<ImageButton
android:id="#+id/increaseTeam2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_plus"
android:contentDescription="#string/plus_button"
android:onClick="increaseScore"
android:background="#drawable/button_background"/>
<TextView
android:id="#+id/score_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:text="#string/initial_score"/>
<TextView
android:id="#+id/team2_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="#string/team_2"/>
</RelativeLayout>
</LinearLayout>
My strings.xml file.
<resources>
<string name="app_name">Scorekeeper</string>
<string name="team_2">Team 2</string>
<string name="initial_score">0</string>
<string name="plus_button">Plus Button</string>
<string name="minus_button">Minus Button</string>
<string name="team_1">Team 1</string>
</resources>
drawable.ic_minus:
<vector android:height="40dp" android:viewportHeight="24.0"
android:viewportWidth="24.0" android:width="40dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M19,13H5v-2h14v2z"/>
</vector>
drawable.ic_plus:
<vector android:height="40dp" android:viewportHeight="24.0"
android:viewportWidth="24.0" android:width="40dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
</vector>
drawable.button_background:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke
android:width="2dp"
android:color="#color/colorPrimary"/>
</shape>
I hope I have not missed anything out. If you copy paste my code inside an empty activity activity_main.xml file, you should see something like this.
Now the problem:
I want to implement some styles for my buttons. I have updated my styles.xml as such. In this case I have a parent ScoreButton which only takes the background, whereas the child elements are the plus and minus, which takes the picture and description.
<resources>
<!-- Base application 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>
</style>
<style name="ScoreButtons" parent="Widget.AppCompat.Button">
<item name="android:background">#drawable/button_background</item>
</style>
<style name="PlusButtons" parent="ScoreButtons">
<item name="android:src">#drawable/ic_plus</item>
<item name="android:contentDescription">#string/plus_button</item>
</style>
<style name="MinusButtons" parent="ScoreButtons">
<item name="android:src">#drawable/ic_minus</item>
<item name="android:contentDescription">#string/minus_button</item>
</style>
</resources>
And if I update one of my button's code as such, for instance, replacing #+id/decreaseTeam1 with the code below:
<ImageButton
android:id="#+id/decreaseTeam1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
style="#style/PlusButtons"
android:onClick="decreaseScore" />
The minus button suddenly becomes inflated.
I read that child views override parent views, but I don't see how that can be a problem, since there is no change to the image size, nor have I compressed it.
The problem is that in the style definition, your ScoreButtons has Widget.AppCompat.Button as parent. This style defines a minHeight and minWidth, as follows:
<style name="Base.Widget.AppCompat.Button" parent="android:Widget">
<item name="android:background">#drawable/abc_btn_default_mtrl_shape</item>
<item name="android:textAppearance">?android:attr/textAppearanceButton</item>
<item name="android:minHeight">48dip</item>
<item name="android:minWidth">88dip</item>
<item name="android:focusable">true</item>
<item name="android:clickable">true</item>
<item name="android:gravity">center_vertical|center_horizontal</item>
</style>
So, in order to solve your problem, you just have to remove the parent from ScoreButtons style:
<style name="ScoreButtons">
<item name="android:background">#drawable/button_background</item>
</style>
You have an error in your style. You are using an ImageButton not a Button
So, you should write
<style name="ScoreButtons" parent="Widget.AppCompat.ImageButton"> // ImageButton
<item name="android:background">#drawable/button_background</item>
</style>
you are making a mistake while assigning a style. you need to use ImageButton instead of using Button.
Use this:
<style name="ScoreButtons" parent="Widget.AppCompat.ImageButton">
<item name="android:background">#drawable/button_background</item>
<item name="android:contentDescription">#string/minus_button</item>
</style>
Instead of this:
<style name="ScoreButtons" parent="Widget.AppCompat.Button">
<item name="android:background">#drawable/button_background</item>
<item name="android:contentDescription">#string/minus_button</item>
</style>

EditText cursor and pointer color for below android 5.0

I am trying to change EditText cursor pointer color (from the primary color blue to white), but no solution is working for my project. I have tried to develop a demo project, where the same code is working fine. This code is working fine for >=android 5.0
I do not know, which attribute is overwritten by my value. I have two options to encounter this problem :
Find the attribute which is controlling that color value.
Change the color value by java code when page loads (in onViewCreated).
Please suggest how to resolve this issue.
styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="my_text_layout_style">
<item name="android:textColor">#FFF</item>
<item name="android:textColorHint">#FFF</item>
<item name="colorAccent">#FFF</item>
<item name="colorControlNormal">#FFF</item>
<item name="colorControlActivated">#FFF</item>
<item name="colorControlHighlight">#FFF</item>
</style>
<style name="my_edit_text_style">
<item name="colorAccent">#FFF</item>
<item name="android:editTextStyle">#style/MyEditTextStyle</item>
</style>
<style name="MyEditTextStyle" parent="Widget.AppCompat.EditText" />
</resources>
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/base_disable_btn_bg_color"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:hint="just a hint"
app:hintTextAppearance="#style/my_text_layout_style"
android:theme="#style/my_text_layout_style"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:theme="#style/my_edit_text_style"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
Tried to add view programmatically but no success
AppLinearLayout appLinearLayout = (AppLinearLayout) view.findViewById(R.id.some_id);
EditText editText = new EditText(new ContextThemeWrapper(getContext(), R.style.AppTheme_Cursor));
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
editText.setLayoutParams(params);
appLinearLayout.addView(editText);
Try this link. For me, it worked.
And, you can find and modify the drawables on your SDK here: Android\sdk\platforms\YOUR_ANDROID_VERSION\data\res at drawables-*dpi.
You can copy and modify their color/form as your wish.
Try this solution:
Use this attribute in EditText: android:textCursorDrawable="#drawable/cursor_color"
In drawable, create : cursor_color.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<size android:width="1dp" />
<solid android:color="#c8c8c8" />
I used this and it's work with me correctly.
<style name="edittext" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorControlNormal">#color/gray</item>
<item name="colorControlActivated">#color/colorAccent</item>
<item name="colorControlHighlight">#color/colorAccent</item>
<item name="android:textColor">#color/white</item>
<item name="android:textColorHint">#color/gray</item>
</style>
<EditText
android:id="#+id/email"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:gravity="center"
android:hint="#string/email_address"
android:inputType="textEmailAddress"
android:padding="#dimen/padding_16"
android:textColor="#color/white"
android:textColorHint="#color/login_color"
android:textCursorDrawable="#color/mdtp_white"
android:theme="#style/edit" />
Use this attribute in your EditText:
android:textCursorDrawable="#null"
You can create your own style/theme for only this EditText and change the ColorAccent :
<style name="EditTextColorCustom" parent="#style/AppBaseTheme">
<!-- Customize your theme here. -->
<item name="colorAccent">#color/colorAccent</item>
</style>
Use this same in style in your values-21 folder.
Make a new drawable.
Here, cursor.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<size android:width="2dp" />
<solid android:color="#EF5350"/>
<stroke android:color="#EF5350"/>
</shape>
and use it in EditText like this:
<EditText
android:id="#+id/ed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/roundedcornerwhite"
android:hint="edit text"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:maxLines="1"
android:singleLine="true"
android:imeOptions="actionNext"
android:textColor="#color/colorPrimaryText"
android:textColorHint="#color/hintcolor"
android:textCursorDrawable="#drawable/cursor"
android:textSize="16sp" />
UPDATED:
just make a new theme like -
<style name="themex" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimaryDark">#666666</item>
<item name="android:listDivider">#color/white_pressed</item>
<item name="colorPrimary">#color/colorIcons</item>
<item name="android:textColor">#b6b6b6</item>
<item name="android:windowDisablePreview">true</item>
<item name="colorControlActivated">#color/olagreen</item>
<item name="android:windowAnimationStyle">#null</item>
</style>
here colorcontrolactivated will be the answer to ur question. And add this theme in to your activity and remove the the style u gave to edittext in ur layout-
<activity
android:name="youractivityname"
android:parentActivityName="com.example.AboutUs"
android:screenOrientation="portrait"
android:theme="#style/themex"/>
UPDATE:
If not working for then, just check whether your fragment is inside the activity and you gave the correct theme to that activity. The fragment will also have this theme. If its not working then try this -
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainlayout"
style="#style/themex"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorIcons"
android:orientation="vertical"
android:weightSum="2">
</RelativeLayout>
i hope this will help you.
I've combined few answers on SO and found the best way to do this:
Look for the original drawable in your android sdk folder
(\android-sdk\platforms\android-23\android.jar\res\drawable-hdpi-v4)
Edit those images with an editor and put them in your drawable folder.
Add following lines to your style:
<item name="android:textSelectHandle">#drawable/my_drawable_handle</item>
<item name="android:textSelectHandleLeft">#drawable/my_drawable_handle_left</item>
<item name="android:textSelectHandleRight">#drawable/my_drawable_handle_right</item>
The result:
<style name="my_edit_text_style">
<item name="colorAccent">#FFF</item>
<item name="android:editTextStyle">#style/MyEditTextStyle</item>
<item name="colorAccent">#FFF</item>
<item name="colorControlNormal">#FFF</item>
<item name="colorControlActivated">#FFF</item>
</style>
This may help you.

How to have Material design buttons with different colors in API 21?

Coming from this thread: Android Material Design Button Styles
I couldn't understand how to individually change the colors of the buttons, so that not all buttons are with the same color.
<item name="android:colorButtonNormal">#color/blue</item>
This solution works nice, but it changes the color of all buttons.
In API 22, we can change the color of the different buttons by using the backgroundTint, like so:
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="3dp"
android:backgroundTint="#color/orange"
android:text="#string/button1_text"
android:textAllCaps="true"
android:textColor="#color/white"
android:textSize="18sp" />
How can we do it in API 21 ?
That's the styles.xml that I have:
<style name="AppTheme" parent="#android:style/Theme.Material.Light">
<item name="android:actionBarStyle">#style/actionBarCustomization</item>
<item name="android:spinnerDropDownItemStyle">#style/mySpinnerDropDownItemStyle</item>
<item name="android:spinnerItemStyle">#style/mySpinnerItemStyle</item>
<item name="android:colorButtonNormal">#color/myDarkBlue</item>
</style>
<style name="actionBarCustomization" parent="#android:style/Widget.Material.Light.ActionBar">
<item name="android:background">#color/white</item>
<item name="android:titleTextStyle">#style/actionBarTextColor</item>
</style>
<style name="actionBarTextColor" parent="#android:style/TextAppearance">
<item name="android:textColor">#color/black</item>
</style>
Okay, I figured it out. Here is the way I solved it, I hope it helps someone else too (I am not saying that it's perfect).
I created a drawable material_ripple_effect.xml that looks like that:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#color/black">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="2dp" />
<solid android:color="#color/myOrange" />
</shape>
</item>
</ripple>
And then in the layout, where I have the button, I just set the ripple drawable as a background. In activity_main.xml:
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="3dp"
android:backgroundTint="#color/orange"
android:background="#drawable/material_ripple_effect"
android:text="#string/button1_text"
android:textAllCaps="true"
android:textColor="#color/white"
android:textSize="18sp" />

Categories

Resources