Touch a button behind an invisible view - android

See the picture, i have a button and it is behind an invisible view (the red line), lets say a gridview, or just simply LinearLayout. Is there any possible way that will let me touch or click the button behind this invisible view? Thank you.
NOTE : i have my reason why i need the button behind the view, i just illustrated it using this picture for you guys to know what i meant. The button has to behind the view :))

android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"
Declare it in your layout.
Let me know if it helps you.

Yes Its possible. Until or unless your invisible view is not clickable. so check your invisible layout structure. make android:clickable="false"

1 way you can do this is:
1. add an onTouch(View view, MotionEventevent) Listener to your layout
2. get the buttons bounds
3. Check if the touch event was done inside the bounds
The code should look something like this:
Button button;
Rect rect;
onCreate(){
rect = button.getClipBounds();
layout.setOnTouchListener(this)
}
onTouch(View view, MotionEvent event){
if(rect.contains(event.getX(), event.getY())
//insert action here
}

Related

Android: Pass touches to the view (Another App) under Floating view

thank you for reading my question.
I make a floating view and it has an image inside.
It is translucent.
I want this floating view just shows its translucent image and doesn't bother me at all.
Pass touches to the view under
I've seen this article and I've done it.
OnTouchListener -> OnTouch -> return false.
clickable = false, focusable = false.
But the touch event doesn't pass through my floating view.
Would it be possible to solve my problem?
Thank you. I'm going to really appreciate it if you could give me just one hint.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:clickable="false">
...
#TargetApi(Build.VERSION_CODES.FROYO)
#Override
public boolean onTouch(View v, MotionEvent event) {
if(!activate){
return false;
}
}
That's not possible. Communication between apps is limited and there is no touch events communication.

Signature not working in Custom ListView

I know for all of you this is a stupid question but it is not something like that.
In my custom listView there is one hidden layout which will be visible when click to button from my listView as a drop down. In that layout i have a one linear layout in which i want to draw signature. For that i have used GestureOverLayView and custom Signture class. But none of them working means signature is not drawing properly. Its just cuts when i tried to draw a signature. To overcome with this i have used
android:focusable="true"
android:focusableInTouchMode="true"
also
android:focusable="false"
android:focusableInTouchMode="false"
Also tried to disable InterceptTouchEvent for ListView on touch of it but none of them are working. So please anyone had faced similar issue before this?
Help in advance would be appreciated !!
I too had the same problem
If you are using View for signature then in onTouchEvent(MotionEvent event)
of view you have write this code Activity.ListView.requestDisallowInterceptTouchEvent(true).
public boolean onTouchEvent(MotionEvent event) {
Activity.ListView.requestDisallowInterceptTouchEvent(true);
*Rest of code here*
return true;
}
Because View will gets confused it's a signature draw or ListView scroll.
This should work

How to change TextView background color when touching in and out of view?

This has to be a very simple fix, but I can't seem to figure it out. I have got my program to change the background color to change onClick, and onTouch with ACTION_DOWN and ACTION_UP. But I need it to change the color when touching the screen and going in and out of the TextView. I need it to function like a mouseOver/mouseOut event. Is there a way to do this on android? Or am I stuck with onTouch, where the action has to start from within the TextView?
Right now I set the onTouchListener on the TextView itself. Should I set it somewhere else and then check if the x and y are within the Textview? Or is there another event listener I should be using? I am new to Android, any help would be appreciated. Thanks.
Mike
I would implement the OnTouchListener on your application and then on the onTouch method, keep checking if the current position of the touch event is within the bounds of the bounding box of the view. If it is, apply the new background and if it isn't apply the original one.
Since all the views implement the setBackgroundColor I didn't do any casting to TextView but the example should suffice, at least as a starting point to develop your application further.
The full code for this is the following:
public class Main extends Activity implements OnTouchListener{
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Set the listener for the parent/container view
findViewById(R.id.cont).setOnTouchListener(this);
//Get a hold of the view and create the Rect for the bounds
View target = findViewById(R.id.target);
Rect b = new Rect();
//Get the bounding box of the target view into `b`
target.getGlobalVisibleRect(b);
}
public boolean onTouch(View v, MotionEvent event) {
//Check if it's within the bounds or not
if(b.contains((int)event.getRawX(),(int) event.getRawY())){
target.setBackgroundColor(0xffff0000);
}else{
target.setBackgroundColor(0xff000000);
}
//You need to return true to keep on checking the event
return true;
}
}
As for the user interface for the previous code, it's just a linear layout with an ID cont and a view (a TextView in your case) with an ID target. The rest is totally by default so there is no point in me pasting it here. Note I only tested this on an emulator and ymmv when trying it on real devices, but as far as I can think of, it should be fine.
Relevant documentation:
getGlobalVisibleRect method
onTouchListener

How to use whole screen as button in android?

How can i get an onClick response when the user touches any part of the screen?
Place a Button inside the layout manager.
and specify
fill_parent
for width and height.
and remove the border of the button.
this will work.
For Example you have ah RelativeLayout means,
RelativeLayout mLyout=(RelativeLayout)findViewById(R.id.layout01);
relativeclic1.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
// Here do your Task
}
});
You can cut off the touch events before they are ever dispatched by overriding dispatchTouchEvent:
https://developer.android.com/reference/android/app/Activity.html#dispatchTouchEvent(android.view.MotionEvent)
You can get the statistics of the touch -- first, repeated, etc -- from the MotionEvent passed.

Can I set something like "tooltip" for a view in android?

Can I set some message to appear like a "tooltip" for a TextView or Button?
There's no concept of "hovering" in a touch screen, but you could set a LongClickListener for your View, and have a Toast appear after a long press. Something like this:
Toast viewToast = Toast.makeText(this, "My View Tooltip", Toast.LENGTH_SHORT);
View myView = (View)findViewById(R.id.my_view);
myView.setOnLongClickListener(new OnLongClickListener() {
#Override
public void onLongClick(View v) {
viewToast.show();
}
});
EDIT: After reading your comment, you should just use the hint attribute in your EditText XML layout:
<EditText
android:hint="My tip here" />
-First set a textview with your hint and set it to invisible.
-Create an animation xml with alpha animation,specify how long you would like to display(at the end set the animation to zero alpha so that it remains invisible) and put it in res->anim folder
-Inside your onCreate and onClick methods of view that need tooltip
set the text view to visible
Hook the animation(like
R.anim.tooltip) to this text view
-Use boolean flags and allow the user to switch off the tool tips in menu.
I'll leave the code specifics to you. You find them easily in stackoverflow.

Categories

Resources