ListView top highlight on scrolling - android

The border displays a default color (that's orange on my Nexus S) while scrolling a ListView to the limit. How to change that color?
I really don't know how to explain it. Just look at this picture:
So, how to change the highlight color when the ListView scrolling to the border? using themes or styles

The solution is to use setOverscrollFooter(null) and setOverscrollHeader(null).
The documentation is here !
You can also set it directly in the XML :
<ListView android:overScrollMode="never" />
Or specify the footer and the header :
<ListView
android:overscrollHeader="#null"
android:overscrollFooter="#null" />
N.B. : There is also a property fadingEdge that may interest you.
"Overscroll" methodes are supported starting API level 9

Finally I found the solution.
setOverscrollFooter(null) and setOverscrollHeader(null) does not work. At least on 2.3.*. Setting attributes from *.xml doesn't help too.
setOverScrollMode(View.OVER_SCROLL_NEVER) causes glitchy scrolling. At least on 2.3.*.
The only solution that really works involves the use of Java Reflection.
It works even with ugly custom Samsung listviews with bounce overscroll effect.
Here is a snippet:
#Override
protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
//onOverScrolled method must be overrided, or we will see the background of the listview when overscroll fast.
}
private void removeOverscrollEffect() {
try {
Class<?> superClass = getClass().getSuperclass().getSuperclass();
Field field = superClass.getDeclaredField("mEdgeGlowTop");
field.setAccessible(true);
Object edgeGlowTop = field.get(this);
if (edgeGlowTop != null) {
Class<? extends Object> edgeClass = edgeGlowTop.getClass();
Field edgeDrawable = edgeClass.getDeclaredField("mEdge");
edgeDrawable.setAccessible(true);
edgeDrawable.set(edgeGlowTop, new ColorDrawable(Color.TRANSPARENT));
Field glowDrawable = edgeClass.getDeclaredField("mGlow");
glowDrawable.setAccessible(true);
glowDrawable.set(edgeGlowTop, new ColorDrawable(Color.TRANSPARENT));
field.set(this, edgeGlowTop);
}
Field fieldBottom = superClass.getDeclaredField("mEdgeGlowBottom");
fieldBottom.setAccessible(true);
Object edgeGlowBottom = fieldBottom.get(this);
if (edgeGlowBottom != null) {
Class<? extends Object> edgeClassBottom = edgeGlowBottom.getClass();
Field edgeDrawableBottom = edgeClassBottom.getDeclaredField("mEdge");
edgeDrawableBottom.setAccessible(true);
edgeDrawableBottom.set(edgeGlowBottom, new ColorDrawable(Color.TRANSPARENT));
Field glowDrawableBottom = edgeClassBottom.getDeclaredField("mGlow");
glowDrawableBottom.setAccessible(true);
glowDrawableBottom.set(edgeGlowBottom, new ColorDrawable(Color.TRANSPARENT));
fieldBottom.set(this, edgeGlowBottom);
}
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
}
I hope this helps.

Here is a nice article on ListView Backgrounds Optimization.
To fix this issue, all you have to do is either disable the cache color hint optimization, if you use a non-solid color background, or set the hint to the appropriate solid color value. You can do this from code (see setCacheColorHint(int)) or preferably from XML, by using the android:cacheColorHint attribute. To disable the optimization, simply use the transparent color #00000000. The following screenshot shows a list with android:cacheColorHint="#00000000"

Use it in XML file--
<ListView ---
android:fadingEdge="none"
---</ListView>
EDITED:
Using fading edges may introduce noticeable performance degradations and should be used only when required by the application's visual design. To request fading edges with API level 14 and above, use the android:requiresFadingEdge attribute instead.
Check this API link

I used kord's answer until it stopped working in Lollipop, so I changed into this:
try {
Class<?> superClass = getClass().getSuperclass().getSuperclass();
Field field = superClass.getDeclaredField("mEdgeGlowTop");
field.setAccessible(true);
field.set(this, new NoEdgeEffect(getContext()));
Field fieldBottom = superClass.getDeclaredField("mEdgeGlowBottom");
fieldBottom.setAccessible(true);
fieldBottom.set(this, new NoEdgeEffect(getContext()));
} catch (Exception e) {
}
class NoEdgeEffect extends EdgeEffect
{
public NoEdgeEffect(Context context) {
super(context);
}
public boolean draw(Canvas canvas) {
// Do nothing
return false;
}
}

you can use android:listSelector="#002234".
In above value can be any color code that you can find on internet easily.

Related

Set default(unfocused) TextInputLayout hint textSize

I am trying to change hint text size programmatically, but I just can't find the right method. I'm using setHintTextAppearance, like it's shown in example, but it works only when input is focused or filled with some data. I tried to set EditText textSize also, but still no luck.
textInputLayout.setHintTextAppearance(Vabaco_TextInputLayout_hint_small);
EditText a = textInputLayout.getEditText();
a.setTextSize(8);
You can change hint text size when it unfocused using reflection like this;
try {
Field filed = TextInputLayout.class.getDeclaredField("mCollapsingTextHelper");
filed.setAccessible(true);
Object helper = filed.get(textInputLayout);
Field f1 = helper.getClass().getDeclaredField("mExpandedTextSize");
f1.setAccessible(true);
f1.set(helper,100);
}
catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
name of mExpandedTextSize may be different according to the dependency version for TextInputLayout. You should check TextInputLayout and CollapsingTextHelper classes for the name of variables.
Hope this helps you.
Reflection solution doesn't work on support:design:28.0.0(mExpandedTextSize-> expandedTextSize). Also, Android Q (and later) doesn't support some non-sdk solutions.
Create your custom layout:
public class CustomTextInputLayout extends TextInputLayout {
public CustomTextInputLayout(Context context) {
super(context);
}
#Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
if(child instanceof EditText) {
((EditText)child).setTextSize(16);
}
super.addView(child, index, params);
}
}
If setting the text size programmatically is not required you can try like below,I have disabled TextInputLayout hint,
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintEnabled="false">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/edittext"
android:hint="yorhint"
android:inputType="text"
android:textColorHint="#color/colorLightBlack"
android:textSize="10sp" />
</android.support.design.widget.TextInputLayout>
If required programmatically you can find edittext by id and set the text size.

underline when writing text in entry view - xamarin,forms android

When I write text in entry view in xamarin.forms I alway have underline under the text
I search all the web for a solution - it was to change the background to null or transparent BUT its not working.
is there any other solution ?
I know this is an old question but it seems to get viewed/asked a lot, and Xamarin still hasn't added built-in support for customizing this very basic UI feature, so I will post an answer here that will hopefully be helpful. Also most answers you will find online (including the Microsoft documentation) show you how to create a static custom renderer, but what we really want is a control where we can set properties in shared code like with any other control. I figured out how to do this so I will share here. I've also included a property for setting border color and width since this is a common UI element we like to set.
In your shared project create a class called CustomEntry (you can rename this later if you wish).
using Xamarin.Forms;
namespace CustomizedControl
{
public class CustomEntry : Entry
{
public Color BorderColor { get; set; }
public int BorderThickness { get; set; }
public bool HasUnderline { get; set; }
}
}
In your Android project create a class called CustomEntryAndroid and paste in this code:
using Android.Content;
using Android.Graphics;
using Android.Graphics.Drawables;
using CustomizedControl;
using CustomizedControl.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(CustomEntry), typeof(CustomEntryAndroid))]
namespace CustomizedControl.Droid
{
public class CustomEntryAndroid : EntryRenderer
{
public CustomEntryAndroid(Context context) : base(context)
{ }
private bool HasUnderline;
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control != null)
{
var element = (CustomEntry)Element;
HasUnderline = element.HasUnderline;
var BorderClr = element.BorderColor.ToAndroid();
if (HasUnderline == false)
{
GradientDrawable gd = new GradientDrawable();
gd.SetColor(Android.Graphics.Color.Transparent);
Control.SetBackgroundDrawable(gd); //this is depreciated but it doesn't matter, the new method SetBackgroud simply calls SetBackgroundDrawable
} //Else maintain default underline
if (BorderClr != Android.Graphics.Color.Transparent)
{
int borderThickness = element.BorderThickness;
if (borderThickness == 0) { borderThickness = 1; } //in case border thickness was not set then default to 1
var brdr = new ShapeDrawable(new Android.Graphics.Drawables.Shapes.RectShape());
brdr.Paint.Color = BorderClr;
brdr.Paint.SetStyle(Paint.Style.Stroke);
Control.Background = brdr;
GradientDrawable gd = new GradientDrawable();
gd.SetColor(Android.Graphics.Color.Transparent);
gd.SetStroke(borderThickness, BorderClr);
Control.SetBackground(gd);
}
}//end if
}//end OnElementChanged
}//end public class CustomEntryAndroid
}//end NameSpace
You can now use the custom entry in any xaml page and get rid of the underline like this:
<local:CustomEntry HasUnderline="False" />
Here is a very simple content page with pretty much nothing on it but an entry:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:CustomizedControl"
x:Class="CustomizedControl.MainPage">
<StackLayout Padding="30">
<local:CustomEntry Text="Test text" WidthRequest="250" HorizontalOptions="Start" HasUnderline="False" />
</StackLayout>
</ContentPage>
Note the import statement xmlns:local="clr-namespace:CustomizedControl". Here is the output:
Now with the underline attribute set to true:
<local:CustomEntry Text="Test text" WidthRequest="250" HorizontalOptions="Start" HasUnderline="True" />
And finally with a border:
<local:CustomEntry Text="Test text" WidthRequest="250" HorizontalOptions="Start" BorderColor="Purple" />
Notice I did not specify a width in the xaml but the border still appeared. This is because I set the default width to 1 in the Android custom renderer. But you can set the width thicker like this BorderThickness="6" or modify the default behavior if you wanted to.
One final note: the namespace I used for this project is "CustomizedControl", so you will of course need to replace "CustomizedControl" with whatever your namespace is.
Take a look here
http://geeks.ms/xamarinteam/2015/04/20/branding-a-xamarin-forms-app-on-android-accent-color/
Your ask was a little obscure, but I think the link above can help you ... you just need to set the underline color for all status as same to the background or transparent.
in Android 5.0 devices, which use the specified accent color you can just change the color, another hand, in androids 4.< you need to create an image

CollapsingToolbarLayout's setCollapsedTitleTextColor and setExpandedTitleColor don't do anything

I'm trying to set the expanded and collapsed CollapsingToolbarLayout's title text color to be different, but no matter what I do, it is always white.
Here is the code in question:
mCollapsingToolbar.setCollapsedTitleTextColor(getResources.getColor(R.color.foo));
mCollapsingToolbar.setExpandedTitleColor(getResources.getColor(R.color.bar));
In my layout XML file, I'm not specifying any color styles on either the AppBarLayout, the CollapsingToolbarLayout, or the Toolbar itself.
Is there some sort of interference with my Activity's theme settings?
Thanks!
I think you need to try below code:
private void changeCollapsedTitleTextColor(CollapsingToolbarLayout collapsingToolbarLayout) {
try {
final Field field = collapsingToolbarLayout.getClass().getDeclaredField("mCollapsingTextHelper");
field.setAccessible(true);
final Object object = field.get(collapsingToolbarLayout);
final Field tpf = object.getClass().getDeclaredField("mTextPaint");
tpf.setAccessible(true);
((TextPaint) tpf.get(object)).setColor(getResources().getColor(R.color.your_color));
} catch (Exception ignored) {
}
}
I found here.
I hope it may help you.

Redrawing EditText after changing InputType

I have made a class that is responsible for monitoring an EditText widget following the Observer pattern. Its sole function is to disable or re-enable auto-correct based on a method call. I am able to successfully achieve this, but the problem is that the new InputType only applies to new text I add to the EditText - old text still retains the red underline to show that it can be auto-corrected.
Is there any way I can force the new InputType to apply to the entire EditText block, and not simply the new content I add? I tried calling editText.invalidate() and editText.refreshDrawableState() in the hope all the text would refresh, but to no avail.
final class SpellCheckerObserver implements EditTextObserver {
public static final int KEY = KeyGenerator.generateUniqueId();
private int defaultInputType;
SpellCheckerObserver(EditTextSubject subject) {
subject.attach(SpellCheckerObserver.KEY, this);
}
#Override
public void activating(EditText editText) {
defaultInputType = editText.getInputType();
editText.setRawInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
}
#Override
public void deactivating(EditText editText) {
editText.setInputType(defaultInputType);
}
}
I found out the answer whilst looking through the source code for TextView, where I came across the removeSuggestionSpans() method.I wasn't aware that the suggestions were in fact a type of span, (unsurprisingly, the SuggestionSpan)
This meant I was able to remove the red underline with the following code:
SuggestionSpan[] spans = editText.getText().getSpans(
0, editText.length(), SuggestionSpan.class
);
if (spans.length > 0) {
for (SuggestionSpan span : spans) {
editText.getText().removeSpan(span);
}
}

PopupWindow z ordering

I play with menus using PopupWindow, which overlap EditText.
It works fine, except that my PopupWindow is overlapped by some items from EditText IME system (selection marks, Paste button).
My question is: how do I force z-ordering of my PopupWindow so that it appears above those decorations?
Here's image of what's happening. I need my PopupWindow (the menu) be drawn on top of everything, thus somehow tell WindowManager how to order windows.
Thanks.
Found anwer myself.
Those decorations are normal PopupWindow-s, managed by EditText.
Z-ordering of any Window is defined by WindowManager.LayoutParams.type, actually it defines purpose of Window. Valid ranges are FIRST_SUB_WINDOW - LAST_SUB_WINDOW for a popup window.
App typically can't change "type" of PopupWindow, except of calling hidden function PopupWindow.setWindowLayoutType(int) using Java reflection, and setting desired window type.
Result:
EDIT:
Code that does that:
Method[] methods = PopupWindow.class.getMethods();
for(Method m: methods){
if(m.getName().equals("setWindowLayoutType")) {
try{
m.invoke(getPopupWindow(), WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL);
}catch(Exception e){
e.printStackTrace();
}
break;
}
}
import android.support.v4.widget.PopupWindowCompat;
PopupWindowCompat.setWindowLayoutType(popupWindow, WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL);
public void compatibleSetWindowLayoutType(int layoutType) {
if (Build.VERSION.SDK_INT >= 23) {
setWindowLayoutType(layoutType);
} else {
try {
Class c = this.getClass();
Method m = c.getMethod("setWindowLayoutType", Integer.TYPE);
if(m != null) {
m.invoke(this, layoutType);
}
} catch (Exception e) {
}
}
}
Make are complement.
The PopupWindowCompat.setWindowLayoutType API must be called before show popWindow.

Categories

Resources