Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>so as @Longwayto said, selector styles are only available for drawables. That doesn't mean it's impossible.</p> <p>Here's a working approach.</p> <p>First you create a custom TextView that extends <code>TextView</code></p> <pre class="lang-csharp prettyprint-override"><code>public class MyTextView: TextView { private readonly Context _context; public FontIconTextView(Context context, IAttributeSet attrs) : base(context) { _context = context; Initialize(attrs); } private void Initialize(IAttributeSet attrs) { var a = _context.Theme.ObtainStyledAttributes(attrs, Resource.Styleable.MyTextView, 0, 0); _touchGlowColor = a.GetString(Resource.Styleable.MyTextView_TouchGlowColor); _touchGlowSize = a.GetInteger(Resource.Styleable.MyTextView_TouchGlowSize, 0); Initialize(); } private void Initialize() { // other initialize stuff happens here... } private int _touchGlowSize; private string _touchGlowColor; public override bool OnTouchEvent(MotionEvent motionEvent) { if (Enabled) { var color = string.IsNullOrEmpty(_touchGlowColor) ? new Color(255, 255, 255, 255) : Color.ParseColor(_touchGlowColor); switch (motionEvent.Action) { case MotionEventActions.Down: SetShadowLayer(_touchGlowSize, 0, 0, color); break; case MotionEventActions.Up: case MotionEventActions.Cancel: SetShadowLayer(0, 0, 0, new Color(255, 255, 255, 255)); break; } } return base.OnTouchEvent(motionEvent); } } </code></pre> <p>then, you have to go into your values directory and specify your custom attributes.</p> <p><strong>Resources\values\CustomBindingAttributes.xml</strong></p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;resources&gt; &lt;declare-styleable name="MyTextView"&gt; &lt;attr name="TouchGlowColor" format="string" /&gt; &lt;attr name="TouchGlowSize" format="integer" /&gt; &lt;/declare-styleable&gt; &lt;/resources&gt; </code></pre> <p><em><strong>All of the above will be reusable across your entire application... no more duplicating shit on every view.</em></strong></p> <p>Lastly, here's how your button will look.</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:local="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"&gt; &lt;!-- obviously the foo/bar is just to show that you add android attrs like normal --&gt; &lt;some.name.space.MyTextView android:foo="foo" amdroid:bar="bar" local:TouchGlowColor="#66e400" local:TouchGlowSize="20" /&gt; &lt;/LinearLayout&gt; </code></pre> <p><em>one gotcha I ran into is setting <code>TouchGlowSize</code> to 30 caused the app to crash. not sure why atm</em></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload