Disable Material Checkbox ripple effect temporarily - java

I have an SpannableString text with links on com.google.android.material.checkbox.MaterialCheckBox view.
I need to disable actual checkbox toggling while user clicks on link in CheckBox text.
I achieved that by caling view.cancelPendingInputEvents() in ClickableSpan's onClick.
However, the ripple effect on the checkbox is still present. I was able to disable it by calling this, also in ClickableSpan's onClick:
var drawable = textView.background
if (drawable is RippleDrawable) {
drawable = drawable.findDrawableByLayerId(0)
textView.background = drawable
}
The problem is, how I should revert this? How to revert default MaterialCheckBox ripple effect after click is done?

Related

Vaadin: Using an image as a button

I wanted to use a image as a button. I got it working, but it is not very well made, please take a look at the screenshot. As you can see the Button itself is a lot bigger than the image, but I wanted it to be as big as the image:
The actual Button is bigger than the Image. The goal here is that there is nothing but the image to click. How can I achieve this? Here is the code ofthe button on the screenshot:
Button testButton = new Button();
String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();
testButton.setIcon(new FileResource(new File(basepath + "/VAADIN/themes/mytheme/img/Button.png")));
loginForm.addComponent(testButton);
I know that
testButton.setStyleName(BaseTheme.BUTTON_LINK)
makes the button invisible, but unfortunately that does not adjust the size of the button, just the visbility..
You can simply add a click listner to an image instead of using a button.
Image image = new Image(null, new ClassResource("/images/button-img.jpg");
image.addClickListener(e -> System.out.println("click"));
image.addStyleName("my-img-button");
And add this css, I use the #Stylesheet annotation to add in CSS.
.my-img-button {
cursor: pointer;
}
It works for me:
Button button = new Button();
button.setStyleName(ValoTheme.BUTTON_LINK);
button.setIcon(new ClassResource("/images/button-img.jpg"));
button.addClickListener(e -> System.out.println("click"));
Maybe you have additional css defined?
Maybe your button is contained in a layout with a fixed height?
Also make sure that your button has no width/height configured, so it can automatically adjust its size to that of the icon image.
The next problem you'll probably run into is the focus border:
Another approach would be to use a layout click listener, and add you own mouse-over/hover/focus styling via CSS.
VerticalLayout layout = new VerticalLayout(new Image(null, new ClassResource("/images/test.png")));
layout.addLayoutClickListener(e -> System.out.println("click"));
With Vaadin 14:
Image img = new Image("src");
Button testButton = new Button(img);
Quite straightforward.

how to implement multi imageView select holding control button in javaFX

In my JAVAFX application, i am having imageviews in a tilepane , i want to implement the multi select like functionality like in android for images . I tried adding border style to the imageView on click event but that didnt work. Is there any way to achieve this.
You can embed the Image in a JavaFX Button, and set the OnAction methods of the Button:
imageButton.setOnAction(new EventHandler<ActionEvent>() {
#Override public void handle(ActionEvent e) {
System.out.println("Changing the color of the button's border :");
imageButton.setStyle("-fx-border-color:blue;");
System.out.println("For further reference, you can save the button or the image in a TreeSet:");
treeSet.add(imageButton);
}
});
If a simple click is enough to select the image, you can define the OnAction method of the Button like above. However if you need a long click (push and hold in Android style) to change the selection status of the image, you can find more information on 'push and hold' click here : how to achieve javafx mouse event "push and hold"? .

Remove shadow below actionbar FragmentActivity

Still can't remove the shadow below the actionbar.
I am using SlidingTabLayout, SlidingTabStrip, and FragmentActivity.
I already tried this:
actionBar.setBackgroundDrawable();
and in SlidingTabLayout:
tabTitleView.setTextColor();
tabTitleView.setBackgroundColor();
However, when setting the background color in tabTitleView the shadow is gone but I don't see the indicator color anymore.
I found solution on the reddit, you should to set windowContentOverlay to #null by defauld in your style.xml
Or try this method from Android SDK to your action bar

Change background color of the button without changing its style

I am stucked in a problem developing an android App.
When the user clicks in a Button, I need to change the background colour of this button. But I need to do in a way that doesn't affects the style, mainly the shapes.
Okay as you have said without changing its style, i think here's what you want,
1.you might be interested in color filters like this
Button btn = (Button) findViewById(R.id.button1);
btn.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0xFFAA0000));
You use different values according to your required colour.If you want to know the constant values of colours, you can refer the documents.
2.you can programmatically set the shade of the entire button using the PorterDuff multiply mode. This will change the button colour rather than just the tint.
For example for a red shaded button
btn.getBackground().setColorFilter(0xFFFF0000, PorterDuff.Mode.MULTIPLY);
For a green shaded button
btn.getBackground().setColorFilter(0xFF00FF00, PorterDuff.Mode.MULTIPLY);
And so on.What it actually does is, it works by multiplying the current button colour value by your colour value.
3.You can also use an online tool like this Android Button Maker to customize your button and use android:background="#drawable/custom_btn" in your layout(inside the <Button> tag) to define the customized button.
Now there are many more ways too to achieve what you want but i think these are some easy and quick fixes you can use.Hope this helps.
Try:
Button myButton = (Button) findViewById(R.id.myButton1);
myButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
myButton.setBackgroundColor(color.Green);
}
});
Try this:
Button btn = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
btn.setBackgroundResource(color.lightblue);
}
});
The easiest way of changing a buttons background is using a state list drawable. This is a xml file where different drawables for the background of the button for different states are defined. An Example:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:constantSize="true"
<item android:drawable="#drawabel/normal"/> // Drawable in normal state
<item android:drawabel="#drawable/pressed"/ android:state_pressed="true"> //Drawabel when pressed
</selector>
Just use android:background="#drawable/background.xml" in the buttons xml or setBackground(R.drawable.background). The framework will do the work for you.

Can't get focus on editText when children are added in layout

i am adding a spinner, an image and an editText in a linearLayout everytime i click a button.
Now whenever i add this layout , editText shows blinking, means it has focus but the keyboard won't show up. Even i click on it, the keyboard won't show up. What most i can do is to click somewhere else and then back at the editText to make it show keyboard and proper focus.
I am using following code, how can i fix this bug.
viewHolder.title = (EditText) view.findViewById(R.id.AddNewDetail);
view.setTag(viewHolder);
layout.addView(view);
i think you should force the softkeyboard show.
((InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE))
.showSoftInput(editText,
InputMethodManager.SHOW_FORCED);
and close it
((InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(editText.getWindowToken(),
0);
and focus on edittext
editText.requestFocus();
May you have added the below line in for your activity in manifeast file
android:windowSoftInputMode="stateHidden"
try removing it or you can manaually use the requestfocus method to get focus. try the below method.
edittext.requestFocus();

Categories

Resources