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
Bitmapfactory.Decodestream Out of Memory Despite Using Reduced Sample Size
Android 4.3: Ble: Filtering Behaviour of Startlescan()
How Disable/Remove Android Activity Label and Label Bar
User Does Not Have Permission to Access This Object . Firebase Storage Android
Android How to Wait Until a Service Is Actually Connected
Commitallowingstateloss() in Fragment Activities
Android Service Startservice() and Bindservice()
How to Get/Set Media Volume (Not Ringtone Volume) in Android
Setting Action Bar Title and Subtitle
How to Repeat Notification Daily on Specific Time in Android Through Background Service
How to Display a One Time Welcome Screen
Items Inside Gridview Getting Repeated When Screen Scrolls
Stop Scrollview from Auto-Scrolling to an Edittext
Combining Two Png Files in Android
Make Android Webview Not Store Cookies or Passwords
How to Get Thumbnail for Video in My /Sdcard/Android/Data/Mypackage/Files Folder