make buttons behind view not clickable - java

I have a linear view in front of some buttons with a background and my problem is that I can still click the buttons on the back of the view even though I can't see them. is there a way I can make the view "solid" so I won't be able to click through its background/borders?

I am not sure why you are not just deleting the buttons but one way you can go about it is disenabling the buttons from your java file using
myButton.setEnabled(false);
or in your xml file using:
<Button
android:enabled="false"
/>

Solved! I just made the view clickable thus making it "solid" and stopping anyone from clicking stuff behind it

Related

Limit the click area on the view android

I need to limit the click area on the view. For example, I have a full-screen view, but I need only the top of the screen to be clickable, while clicking on the bottom should not give a result, how can I implement this? adding on top of the container doesn't help
You will need to create a click listener ONLY on the view you want to respond.
TopView.setOnClickListener()
BottonView (nothing).
If for some reason, your top View is not independent, just create another view that is transparent, and set a clickListener on that.

Android: Using both adjustPan and adjustResize doesn't work but I need both

I haven't officially decided if I want to head this route or not but I have an adview in my XML document. The XML document contains a Relative layout that contains a ScrollView and and Adview. The Adview sticks to the bottom of the relative layout while the scrollview is everywhere else.
When a user focuses on an edittext inside of my app, some of the page would be cut off. I fixed that by adding:
android:windowSoftInputMode="adjustPan"
But then the problem became that my AdView gets cut off everytime the user has the keyboard open. So to fix that issue I changed the Android Manifest to:
android:windowSoftInputMode="adjustResize"
Which kept the AdView on top of the keyboard, but now the Adview covers some of the content on the app. I was wondering if there was a way to have my app content not be covered and keep the AdView above the keyboard when it appears?
I have tried this but it did not work:
android:windowSoftInputMode="adjustPan|adjustResize"
Not sure if I actually want to go that route, I just want the choice. It kind of looks annoying in my opinion.
You can't set adjustPan and adjustResize at the same time. They mean completely different and conflicting behaviours. They only affect how your root view behaves when the keyboard appears or disappears.
adjustPan means "When the keyboard appears, if a view behind the keyboard gains focus, move the view up so that the user can see it" but it doesn't allow the user to move the view around themselves.
adjustResize means "When the keyboard appears, change the height of the view to fit above the keyboard". That doesn't mean that your view will adapt correctly to fit in that space - that's your job.
It sounds like what you're trying to do is have a ScrollView above the advert which is stuck to the bottom of the root RelativeLayout view. In your case, you definitely want to use adjustResize to cause the RelativeLayout to resize to a shorter height. This in turn moves the advert up to the top of the keyboard as you described. Then you have to make sure that the main ScrollView is always above the advert and not somehow tucked behind it. You probably want a layout that looks something like this:
<RelativeLayout
android:layoutWidth="match_parent"
android:layoutHeight="match_parent">
<ScrollView
android:layoutWidth="match_parent"
android:layoutHeight="match_parent"
android:layoutAbove="#+id/advert_view">
<!-- Your scrolling views go here -->
</ScrollView>
<AdvertView
android:id="#id/advert_view"
android:layoutWidth="match_parent"
android:layoutHeight="wrap_content"
android:alignParentBottom="true" />
</RelativeLayout>
Note that the ScrollView says it wants to be the height of the parent, but laid out above the AdvertView. This will mean it isn't behind the AdvertView at the bottom edge and you'll be able to scroll to anything that exists inside the ScrollView.

Scroll View in Android shows up when I scroll it

I have a Scroll-view layout, which is, say my main menu, when user clicks on an item I want to make my menu disappear, and show the contents that user wants!
everything works fine, I use this code:
mainMenulay.setVisibility(View.Gone);
but, when I touch the screen, and swipe the screen (like scrolling when it was actually visible), where the main menu was located, the scroll-View show up in an unwanted buggy way !
its not functional, but it shows up !
I have fixed this issue with Z Order and defined a background and have brought it in front of the Main Menu and it wont show up, but I'm curious to know what's wrong, how to avoid it ?!
If you have questions about How I defined the Scroll-View, well. it looks like this:
<ScrollView
android:id="#+id/main_menu_lay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="61dp"
android:layout_marginTop="65dp"
android:visibility="visible" >
Thanks in Advance :-)
I've seen other people with the same problem, but only when an animation i used to hide the view.
android View with View.GONE still receives onTouch and onClick
and
Unable to make view completely GONE after using TranslateAnimation
Probably, you can take a look at
View.setClickable();
and
ViewParent.requestDisallowInterceptTouchEvent()

Creating an overlay activity

I am trying to create a overlay activity which is sitting in a corner of the screen taking a very small portion of the screen, while the rest of the screen is interactive that is I tap on anything that is displaying on rest of the screen. So far I am unsuccessful in obtaining my goal. I have added these properties to my window but they don't seem to work.
hello.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="50dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/tepp" >
</RelativeLayout>
What can I do to solve this problem?
From what I can remember, only one Activity can be active at any given time. So while that small Activity in the corner is running, the other activitys will be paused and you wont be able to interact with them. You should try using a Fragment instead. You can have multiple fragments visible at the same time. Although I believe that only one Fragment can be active at any given time like an Activity, when you click on different fragments, the one you click on becomes active and you can interact with it. This might help you achieve what your looking for.
i don't think that there is such a thing "an overlay activity" .
however, instead of using an activity, you could make the view on top, like i've shown here . when the user touches it, you would need to decide what would happen, and if you need to expand its size to be larger to show something else to the user...
btw, if all the activity does is to create an on top view, you can call finish() right at the end of the onCreate() method. also you can avoid using setContentView in case you inflate the view anyway...

Android Row becomes Unclickable with Button

I have a listView, where each row has a button in the row layout. However, this seems to make the row itself unclickable. How can I make both the button and row clickable?
Thanks.
You need to set itemsCanFocus on the list like this:
mList.setItemsCanFocus(true);
To make the button clickable. Then you will need to use your own adapter and in getView return a view which is Clickable and focusable. You will also lose the default highlight states so you need to put them back in with the background resource. So do this:
view.setClickable(true);
view.setFocusable(true);
view.setBackgroundResource(android.R.drawable.menuitem_background);
to your view before returning your view.
Whenever I see posts concerning the android:focusable and android:clickable attributes, I always see them being both set to the same value at once. I figured there must be a reason if they are two separate attributes instead of being one.
It turns out that a much better way of achieving your desired behavior is to set
android:focusable="false"
or
yourButton.setFocusable(false)
on the Button in your View. Once you do that, you'll be both able to set an OnClickListener on the Button, and a click on the row will fire the onListItemClick() method in your OnItemClickListener.
Try to set your widgets to non clickable and non focusable in xml,the click on items will work normally and also the click on button will work normally.
android:clickable="false"
android:focusable="false"
Hope this helps.
Unfortunately I don't think that is possible. You ListView row can either have focusable widgets, like a button, or be clickable, not both. See link.

Categories

Resources