Changing background colour for the Selected Tab - android

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);

Related

Textview with background color

I am new to android. I got stuck while doing an application.I have taken 5 textviews with time slots,I would like to show that when I click one text view it should change its background color and when I click another textview the first text view's background color has to disappear and present text view's color has to be highlight.
Here I am posting my code:
public void onClick(View v) {
switch (v.getId()){
case R.id.time_slot_one:
setTimeSlotOne.setBackgroundColor(Color.parseColor("#bdbdbd"));
break;
case R.id.time_slot_two:
setTimeSlotTwo.setBackgroundColor(Color.parseColor("#bdbdbd"));
break;
case R.id.time_slot_three:
setTimeSlotThree.setBackgroundColor(Color.parseColor("#bdbdbd"));
break;
case R.id.time_slot_four:
setTimeSlotFour.setBackgroundColor(Color.parseColor("#bdbdbd"));
break;
case R.id.time_slot_five:
setTimeSlotFive.setBackgroundColor(Color.parseColor("#bdbdbd"));
break;
}
A simple way would be to create a disable Background function that will be called each time you click a new one.
public void removeBackgroundColors() {
setTimeSlotOne.setBackgroundColor(Color.WHITE);
setTimeSlotTwo.setBackgroundColor(Color.WHITE);
setTimeSlotThree.setBackgroundColor(Color.WHITE);
setTimeSlotFour.setBackgroundColor(Color.WHITE);
setTimeSlotFive.setBackgroundColor(Color.WHITE);
}
now simply change your code to:
case R.id.time_slot_two:
removeBackgroundColors();
setTimeSlotTwo.setBackgroundColor(Color.parseColor("#bdbdbd"));
break;
...
Even simpler is to call it before your case statement, depending on what actions you want to take.
Use if else to setBackground color, for example ; if onclick of firsttextview set its color and on click of second change firsttextview color and set seconds color
You have to change the color of all Textviews.
Example t1 is selectable change t1's color as selected and other textviews as unselected,so on for rest of the textviews
It would be better if you use radio group which handles all clicks and selection and highlighting if you have many textviews.
Please check below url.
Url
In that link use answer by Sanjeet Ajnabee. It is excellent. I have been using it.

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
}
});

how to zoom-in interface? Android development

In my Android application, I have an activity with three layouts: A left layout, a middle layout, and a right layout.
The right layout is the main one. I want the right layout to zoom into fullscreen when I click a button. If you have the specific code,it's better.
Thanks very much!
If I got your question right:
Your button's OnClickListener should look like something like this:
OnClickListener listener = OnClickListener() {
public void onClick(View v){
findViewById(R.id.left_layout).setVisibility(View.INVISIBLE);
findViewById(R.id.center_layout).setVisibility(View.INVISIBLE);
};
This by itself will not get your right layout to fullscreen. You'll need to add something the below to your right layout for it to "auto fullscreen":
android:layout_width = "0dp";
android:layout_weight = "1";
if you don't do that, you'll have to resize the right layout from the "listener" above.
Hmm, the question is vague, but if I understand correctly, what you want to do is hide the left and center layouts when a button is clicked, so that the right layout becomes full-screen?
Without more details, it's not easy to give you a more precise answer (please post your current layout), but I would do something like:
// this code in your Activity:
// this method is bound to button onCLick (android:onClick="clickButton")
public void clickButton(View view) {
findViewById(R.id.left_layout).setVisibility(View.INVISIBLE);
findViewById(R.id.center_layout).setVisibility(View.INVISIBLE);
}
And to revert back to a 3-layout display, you do the opposite (View.VISIBLE)

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.

Android onClick(View v) not working?

I'm new to Android. I'm stuck at a point and would really appreciate it if anyone could please help me. I'm developing an app which has a grid of colored rectangles. These are created by changing the background colors of a number of TextViews. There are 3 Buttons which cause the background color to change according to some algorithm. There are also 2 TextViews which show the current status of the game.
Now the problem is I have a button example (one of the three buttons) which is supposed to change the background color of the rectangles.
example.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
status_val.setText("true board-example working");
level_1_true();
}
});
The level_1_true() method sets the background color of the rectangles. The above code results in an "activity not responding" dialog being shown, and the OnClickListener does not change the view. Someone suggested I try the runOnUIThread method in activity, but I can't get it to do what I want it to do.
How do I change the view of the screen by clicking the button?
Maybe you can try adding in your button xml code android:onClick="onClickMethod" and adding in your activity
public void onClickMethod(View v) {
status_val.setText("true board-example working");
level_1_true();
}
How did you define status_val? You remeber to link it like this?
status_val=(TextView)findViewById(R.id.);
Please tell me if I can be of more help

Categories

Resources