I have a problem when selecting the text inside an EditText control inside an AlertDialog.
When I select the text, the text selection toolbar shows up at the top of the screen. The problem is that the toolbar background is white, and the icons displayed in the toolbar are also white. Therefore, the icons are not visible (but they work if you touch them). This is on Android 4.2.2 (API 17).
This is the snippet of code I use to create the AlertDialog that contains the EditText. It is located in the onCreate method of my test project's activity.
EditText et = new EditText(this);
et.setText("Test");
AlertDialog.Builder b = new AlertDialog.Builder(this);
b.setView(et).setPositiveButton("Ok", null).setNegativeButton("Cancel", null);
b.create().show();
Here is how the text selection toolbar looks when the text is selected:
How can I change the color of the toolbar and/or icons so that they will be visible?
I think you can use:
<item name="actionModeBackground">#drawable/background</item>
<item name="android:actionModeBackground">#drawable/background</item>
in your main theme. I'm not sure you can point at colors rather than at drawable. A quick workaround is defining a shape drawable. To be more precise you could have a drawable/background.xml like:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid
android:color="#color/color" />
</shape>
Related
when in my drawable layout (custom_button), codes are correct and the shape along with color pop on screen but when I use it in my activity layout (interface of my first page of app), the corners are good but the color I chose was not applied even though my code is correct.
this is my code:
<solid android:color="#00FFDD"/>
<corners android:radius="20sp"/>
If you are using a material theme, the button will have a tint that will change the button's background color.
You can simply remove the tint by adding this line to your button's xml code in your activity :
app:backgroundTint="#null"
I am changing my app's design infrastructure to Material Design Components and would like to achieve something like this:
This is from toggle button and it shows that a drawable can be colored partially, but there is no implementation example how to achieve this. In my app I have a text formatting toolbar with foreground color and I need to get shown the selected text color exactly in that way.
You can split icon into 2 parts (same sized), for example we can take "format color text" icon from material icons
and then simple combine two drawables into one using <layer-list> (LayerDrawable)
ic_format_color_text.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/ic_format_color_text_black_part1_24dp" />
<item android:drawable="#drawable/ic_format_color_text_black_part2_24dp" />
</layer-list>
Now, this drawable can be used as an icon for your button (MaterialButtonToggleGroup + MaterialButton). To tint "bottom shape" part only:
val dr = (colorTextBtn.icon as? LayerDrawable)?.getDrawable(0 /* colored shape layer index*/)
dr?.let { DrawableCompat.setTint(dr, /* color */) }
In My Bottom navigation bar, I am using an icon in the menu XML, the icon color changed with the theme color when selected.
after the tab click the icon totally change I am totally stuck why this happens with the png image.
Bottom navigation
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/white"
app:labelVisibilityMode="labeled"
app:itemBackground="#color/transparent"
app:itemTextColor="#color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="#menu/bottom_navigation_main" />
Selector
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/ic_compas"
android:state_checked="false"/>
<item android:drawable="#drawable/discover_green"
android:state_enabled="true"/>
</selector>
Bottom_nav_menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/chatMenuFragment"
android:enabled="true"enter code here
android:icon="#drawable/chat_selector"
android:title="Chat"
app:showAsAction="always" />
<item
android:id="#+id/contactsFragment"
android:enabled="true"
android:icon="#drawable/people_selector"
android:title="People"
app:showAsAction="always" />
<item
android:id="#+id/discoverFragment"
android:enabled="true"
android:icon="#drawable/discover_selector"
android:title="Discovery"
android:backgroundTint="#color/white"
app:showAsAction="always|withText" />
<item
android:id="#+id/myProfileFragment"
android:enabled="true"
android:icon="#drawable/user_selector"
android:title="My"
app:showAsAction="always|withText" />
</menu>
screenshots
Before selection:
After selection:
I ran into a similar issue, the problem is that by default the bottom navigation view adds a tint to the drawables and fills everything that is not transparent (like the case of your assets).
try adding this line
bottomNavigationView.itemIconTintList = null
"#drawable/discover_green" check this drawble , is it what you you're getting after pressing the compass ?
you're using a state list drawable so when you press compass the icon changes to discover_green, it is same as you defined.
The solution is the completely delete the state list drawble and use just the icon or changed the green dot icon to something you want to use.
The problem is that selected state apply color filter for whole not transparent part of icon. To fix your selected icon you have to make arrows on green circle transparent not white. Ask designer for change it or do it in some editor by your own.
Your problem arises from the fact that discover_green.png file has no transparent area. So when the menu item is selected the green tint is applied to the whole image hence you see a green circle.
However in ic_compas.png everything except the compas is transparent, Meaning if you use it as icon the compas in image will turn green when selected. For this you will have to modify the Discovery menu item as
<item
android:id="#+id/discoverFragment"
android:enabled="true"
android:icon="#drawable/ic_compas"
android:title="Discovery"
app:showAsAction="always|withText" />
This will give you a grey compas if item is not selected and a green compas when selected.
You have to create color icon and simple icon both and at selection time you have to change icon form plain to color and on not select time you have to change color icon to plain icon this is the simplest way to do that.
You can delete the white filter on the drawable item (png or vector) with this code (but you cant colour the icons on touch):
bottomNavigationView.itemIconTintList = null
I have an unusual problem in my application. I am using Material Spinners' library and when I select an item from dropdown menu, I get this weird orange background color.
Example:
I have exact same problem on my Caldroid calendar and it only happens for the background color when I click an item. I don't have this color set in my values and I don't know what to do. I need to change this color to something that is more suitable for my application.
I tried changing the colorPrimary, colorHighlighted and stuff like that in the AppTheme but it was no use.
Any help is very much appreciated!
You can do it by creating a custom selector and set as background of spinner.
First create xml file custom_slector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:drawable="#color/selected_item_color" />
<item android:drawable="#android:color/default_color" />
</selector>
Then set this as your background in spinner
android:background = "#drawable/custom_selector"
android:drawSelectorOnTop = "true"
I have a lot of custom views and I have style for state_pressed. Basically its a rectangle with
solid android:color="#DC2D5A8C"
What I am trying to do is simulate the blue background color that comes with the standard views/controls. For example: when you click on a button or list view item, the background changes to blue (on_pressed).
I got that to work with the above style, but the problem is let's call it the tint effect. In a button, the text caption is black. When you press, the background is blue and the text color changes to white.
Now how can I achieve such a so called "tint" change in my custom control's view?
Your response is much appreciated.
Thanks!
You can use selector xml file to do this.You must be setting background to the button.Instead of that set the xml file to its background.Create selector.xml file in your drawable folder as shown below and set that xml file as background to that button just like : android:background="#drawable/selector"
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected, use blue -->
<item android:drawable="#drawable/btn_blue"
android:state_pressed="true" />
<!-- When not selected, use black-->
<item android:drawable="#drawable/btn_black"/>
</selector>
By doing this you will get so called tint effect to your button.Hope this will help you.