title: Drawable selector loses hover state when clicking with a physical mouse
body: <p>I created a custom drawable (base on a drawable selector) for a regular <code>Button</code> and I decided to test my app with both a physical mouse and keyboard.</p>
  
  <p>That's when I noticed that every time I click the button with the physical mouse, it loses the <code>hovered</code> state for a very brief moment and only after a few milliseconds it gains the <code>pressed</code> state.</p>
  
  <p>Even though this happens only for a very brief moment, it produces an annoying and very noticeable "blink".</p>
  
  <p>I do not know if I made myself clear, so I will reproduce the steps:</p>
  
  <p>1 - Button is idle, and the mouse pointer is not over the button: button renders ok with the default state</p>
  
  <p>2 - I move the mouse cursor over the button and I leave the mouse still: button renders with the hovered state</p>
  
  <p>3 - I press the mouse's left button: button renders with the default state (not hovered) for a brief moment and then renders with pressed state, producing a visual blink</p>
  
  <p>That weird behavior can be easily reproduced/verified by replacing the button with a custom <code>Button</code> class overriding drawableStateChanged():</p>
  
  <pre><code>    @Override
      protected void drawableStateChanged() {
          super.drawableStateChanged();
          final int[] states = getDrawableState();
          StringBuilder builder = new StringBuilder("@@@ ");
          if (states != null) {
              for (int i = states.length - 1; i &gt;= 0; i--) {
                  switch (states[i]) {
                  case android.R.attr.state_pressed:
                      builder.append("p");
                      break;
                  case android.R.attr.state_focused:
                      builder.append("f");
                      break;
                  case android.R.attr.state_hovered:
                      builder.append("h");
                      break;
                  }
              }
          }
          System.out.println(builder.toString());
      }
  </code></pre>
  
  <p>Logcat shows:</p>
  
  <pre><code>@@@     [the button is in the default state]
  @@@ h   [the button is in the hovered state]
  
  [I physically click the left mouse button]
  
  @@@     [the button goes back to the default state even though it *is* hovered and pressed]
  @@@ p   [after a visual blink, the button goes to its pressed state]
  ...
  
  </code></pre>
  
  <p>I tried almost everything: overriding <code>onHoverChanged()</code>, <code>setHovered()</code> and so on... I have even tried to call <code>isHovered()</code> within <code>drawableStateChanged()</code> to see if there is a difference... Nothing!!!! Android actively changes both the drawable state and the <code>hovered</code> attribute to false before setting the pressed state. That's on purpose!</p>
  
  <p>I looked everywhere on the web, and even here at SO. Nothing! It's like no one has noticed it yet, or I must be forgetting something really simple...</p>
  
  <p>FYI: I am not using any libraries (like AppCompat etc etc etc). It is a plain button, placed in a plain Activity. Tested on a Samsung A5 2017 (with USB mouse) and on an Asus Chromebook Flip C100 (using the track pad).</p>
  
  <p>FYI 2: The style in effect is <code>v21/styles.xml</code>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;resources&gt;
  
      &lt;style name="AppBaseTheme" parent="@android:style/Theme.Material.Light.NoActionBar"&gt;
          &lt;item name="android:colorPrimary"&gt;#ff3344bb&lt;/item&gt;
          &lt;item name="android:colorAccent"&gt;#ff3344bb&lt;/item&gt;
          &lt;item name="android:colorControlNormal"&gt;#ff6d6d6d&lt;/item&gt;
      &lt;/style&gt;
  
  &lt;/resources&gt;
  </code></pre>
  
  <p>FYI 3: I also tried to override <code>onGenericMotionEvent()</code>. Again, as soon as I click the button logcat shows <code>@@@ HEXIT</code>. Soon after that, logcat shows <code>@@@ HENTER</code>... but I never even moved the mouse cursor by one pixel... let alone moving it outside the button!</p>
  
  <pre><code>    @Override
      public boolean onGenericMotionEvent(MotionEvent event) {
          switch (event.getAction()) {
          case MotionEvent.ACTION_HOVER_ENTER:
              System.out.println("@@@ HENTER");
              break;
          case MotionEvent.ACTION_HOVER_EXIT:
              System.out.println("@@@ HEXIT");
              break;
          }
          return super.onGenericMotionEvent(event);
      }
  </code></pre>
  
  <p>How can I get rid of that behavior? Does anyone know a flag or a hack to disable this blink?</p>
  
  <p><strong>Important</strong>: I do not want to use the only workaround I came up with so far: create private flags to manually control the hovered state, ignoring Android's hovered state and using timers/scheduled delays/etc.</p>