0

As I am working on keyboard, we know on default keyboard on any android device when we click any button larger image is flashed above button, I don't know exactly this effect, ut I have tried using below code.

Button which is clicked in my Keyboard.xml:

 <Button android:id="@+id/xBack" 
         android:background="@drawable/back_high"/>

Above back_high is my xml file.

back_high.xml file is,

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/back_click"
          android:state_pressed="true" />
    <item android:drawable="@drawable/back"
          android:state_focused="true" />
    <item android:drawable="@drawable/back" />
</selector>

Its working successfully, but image is flashed at same place where I clicked, but I need this image is displayed on above button, as happening on android default keyboard.

Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120
Aniket
  • 2,204
  • 5
  • 34
  • 51
  • 1
    @l7colwinters is correct - you need a separate popup for the flashed image. You are setting the background of the same view - irrelevant for your purpose. – Amir Uval Jun 17 '13 at 17:36
  • @uval alright i have implemented the popup and its working fine for me. but i have one issue, i need coordinates of my current clicked view, because i have to show separate image on touch over the specific button. – Aniket Jun 19 '13 at 06:42
  • Try to get the coordinates from the onTouch event object – Amir Uval Jun 19 '13 at 07:00
  • exactly i tried this, event.getRawX(); as it gives me x coordinates in root layout but it gives different coordinates if i clicked different places on same view – Aniket Jun 19 '13 at 07:11
  • I thought that's what you wanted. You can get the location of the touched view as well: http://stackoverflow.com/questions/3619693/getting-views-coordinates-relative-to-the-root-layout – Amir Uval Jun 19 '13 at 08:58
  • Thanks i also got another way to get coordinates by calling getLeft() on view object.. – Aniket Jun 19 '13 at 09:29

2 Answers2

0

your setting the background of that specific button, so if you want it to appear above the button make sure you use a frame layout as the overall layout of the keyboard and then have a single extra imageview that you switch location and resource when you click on a button. you won't need the selector anymore.

Frame layout's will let you put multiple views on top of each other.

L7ColWinters
  • 1,342
  • 1
  • 14
  • 31
  • alright i have implemented the popup and its working fine for me. but i have one issue, i need coordinates of my current clicked view, because i have to show separate image on touch over the specific button. – Aniket Jun 19 '13 at 06:47
0

This Link :

Why not make this programmatically and not in UI mode?

There are several, depending on what kind of flashing you mean. You can, for example, use alpha animation and start it as your button first appears. And when the user clicks button, in your OnClickListener just do clearAnimation().

Example:

public void onCreate(Bundle savedInstanceState) {
    final Animation animation = new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible
    animation.setDuration(500); // duration - half a second
    animation.setInterpolator(new LinearInterpolator()); // do not alter animation rate
    animation.setRepeatCount(Animation.INFINITE); // Repeat animation infinitely
    animation.setRepeatMode(Animation.REVERSE); // Reverse animation at the end so the button will fade back in
    final Button btn = (Button) findViewById(R.id.your_btn);
    btn.startAnimation(animation);
    btn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View view) {
            view.clearAnimation();
        }
    });
}

Also This Answer.

Community
  • 1
  • 1
Saeid
  • 2,261
  • 4
  • 27
  • 59