How to Keep a Button as Pressed After Clicking on It

How can I keep a button as pressed after clicking on it?

Use the following code. It's useful.

mycodes_Button.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
mycodes_Button.setPressed(true);
return true;
}
});

How do I make a button stay Pressed after clicking

my sulotion (need to use a Directive)

--html

button.component.html

<button  class="btn btn-danger" style="width: 110px" appButton"
></button>

--Typescript

button.directive.ts

@Directive({
selector: '[appButton]'
})
export class ButtonDirective implements OnInit {

constructor(private elRef: ElementRef, private renderer: Renderer2) {

}

ngOnInit() {
}

@HostListener('mousedown') onmousedown(eventData: Event) {
if (this.elRef.nativeElement.style.backgroundColor === 'blue') {
this.renderer.setStyle(this.elRef.nativeElement, 'background-color', 'rgba(200,0,0,0.7)');
} else {
this.renderer.setStyle(this.elRef.nativeElement, 'background-color', 'blue');

}

}

repeat the click only on the last button pressed in jquery

I just wrote a html code for you with jQuery and Bootstrap

You just need to create a new setTimeout function to click the same button again, on first click of the respective button.

This will create a loop and keep your one of the last clicked button automatically clicking.

$(function() {
let theTimeout;
let clickNo = 0;
console.log("Btn function");
$(".btn-to-click").on("click", function() {
clickNo++;
let btnElement = this.getAttribute("id");
console.log("Button clicked with id " + btnElement + " => " + clickNo);
clearTimeout(theTimeout);
theTimeout = setTimeout(() => {
$(`#${btnElement}`).trigger("click");
}, 1000);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div class="container">
<button class="btn btn-primary btn-to-click" id="click-me-1">
click me one
</button>
<button class="btn btn-success btn-to-click" id="click-me-2">
click me two
</button>
</div>

A button remains in pressed state after being clicked

Assuming you mean "doesn't get its original style until something else is clicked":

Change the :focus rule.

Clicking on a control will give it the focus until something else move the focus somewhere else.



Related Topics



Leave a reply



Submit