Can I set something like "tooltip" for a view in android? - 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.

Related

Changing background colour for the Selected Tab

This is my Screen layout, and i want to do this, when I clicked on Popular tab, then Popular block should turns Blue.
Same for the Price, Time and Duration tab.
I've tried to do with Linear Layout but it doesn't.
i have taken it in Text View, and the vertical and Horizontal Lines are used using View tag and I have not use TabLayout, just to make it simple I just used TextView With Background.
Please suggest me a proper solution with code if you can.
Any help would be Appreciated.
In your xml file add following line in your TabLayout,
app:tabBackground="#0000FA"
by this you can chage color of selected tab.
If you have used TextView then just simply create or add this method to you java file & call it from each textviews onclick event by passing the textview to it.
public void changeTabColor(TextView tvSelected){
tv1.setBackgroundColor(Color.White);
tv2.setBackgroundColor(Color.White);
tv3.setBackgroundColor(Color.White);
tvSelected.setBackgroundColor(Color.Blue);
}
try this :
public void onClick(View v) {
switch (v.getId()) {
case R.id.popular_tab:
ResetTabColor();
popular_tab.setBackgroundColor(Color.blue);
case //Do the rest with other tab
}
}
private void ResetTabColor(){
popular_tab.setBackgroundColor(Color.TRANSPARENT); // or white color
time_tab.setBackgroundColor(Color.TRANSPARENT);
duration_tab.setBackgroundColor(Color.TRANSPARENT);
price_tab.setBackgroundColor(Color.TRANSPARENT);

How do I programmatically check an Android radio button with ripple animation?

tl;dr: When the user clicks an unrelated text view, I want a radio button to be selected with a ripple animation. performClick doesn't do this. What should I be doing instead?
I have a radio button with both a label and a longer description.
The general structure of my layout is this:
<RadioGroup>
<RadioButton
id="#+id/officialBusinessRadio"
text="Official business" />
<TextView
id="#+id/officialBusinessCaption"
text="This operates under a ..." />
<!-- ... -->
</RadioGroup>
I've added an OnClickListener to the text view so that tapping on the caption selects the radio button:
officialBusinessCaption.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
officialBusinessRadio.performClick();
}
});
When I tap on the radio button itself or on its own text ("Official Business"), the radio button animates to selected and a ripple ink effect occurs. When I top on the caption text (and performClick is called), the radio button still animates to selected, but no ripple occurs.
Is there a more correct way to get this effect? That is, is there a better way to forward a click on the caption text view to the radio button? If not, is there a straightforward way to trigger the ripple effect on the radio button programmatically?
I would prefer against setting all the text using a string resource for the following reasons:
I intend on styling the label and the caption differently.
I want the radio vertically center aligned with the first line of text.
I've hit this problem by population RadioButtons in a RecyclerView. All of them are set to isClickable = false because I override their selection according to another rule, but the way to trigger the selection to true is doing:
Kotlin:
radioButton.post {
radioButton.isChecked = true
}
Java:
radioButton.post(new Runnable() {
#Override
public void run() {
radioButton.setChecked(true);
}
})
before, I was doing setChecked(true) only and it wouldn't work.

Touch a button behind an invisible view

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
}

Making custom android views "tappable" with a feedback highlight

I'm using a custom view expanded from a XML layout in a horizontal scroll view as a sort of horizontal image list but I'm not sure how to get them to appear clickable/tappable (ie they highlight when tapped) or how to capture these events. I think I've tried setOnClickHandler without it working. I'm also trying to get a simple TextView to do the same. I've also tried setting android:clickable="true" but that hasn't helped either. Any ideas?
To take care of the visual feedback use an xml Selector, and set it as the View's background.
To handle click events use
mView.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//your code here
}
});

ListView item selection

I have a ListView with custom list items. Each list item consists of 2 linear layouts one next to other.
LinearLayout 1 | LinearLayout 2 |
I've declared state list drawables for both LinearLayouts where in state_pressed I'm changing the background of the LinearLayout.
And here comes the issue - When the user taps on the LinearLayout2 only the background of LinearLayout2 should be changed, the background of LinearLayout1 should remain unchanged. On the other hand, when the user taps on LinearLayout1, only the background of LinearLayout1 should be changed. But now when the user taps on either of both LinearLayouts, both of them change their background.
The behaviour on tap on LinearLayout2 should be as onListItemClick() while when the user taps on LinearLayout1 a Dialog should appear (if this matters).
Any ideas how could I solve the background change issue? I've tried playing with focusable and clickable options. If i set clickable=true to both LinearLayouts, the children (TextViews) of LinearLayout2 do not change their colour (the TextViews should change their text colour).
Thank you!
This is because when using a list view you have to change some tags in XML to make the background transparent so that it will correctly work with your back ground.
Add this to your ListView XML code.
android:cacheColorHint="#00000000"
To set the ListView's background to transparent.
Well I think a single solution if you are using BaseAdapter as extends
First give unique Id to both those Layouts in you xml file and add
android:clickable="true"
In your method
public View getView(int position, View convertView, ViewGroup parent) {
when your are getting those views like
holder.layout1_name=(LinearLayout)view.findViewById(R.id.layout1);
holder.layout1_name.setOnClickListener( clicklayout1);
holder.layout2_name=(LinearLayout)view.findViewById(R.id.layout2);
holder.layout2_name.setOnClickListener( clicklayout2);
Add click listener on them
private OnClickListener clicklayout1 = new OnClickListener() {
public void onClick(View v) {
//Do what you want to do here
}
};
private OnClickListener clicklayout2 = new OnClickListener() {
public void onClick(View v) {
//Do what you want to do here
}
};
May be this may help you

Categories

Resources