Set disable button android

Buttons

A button consists of text or an icon (or both text and an icon) that communicates what action occurs when the user touches it.

Depending on whether you want a button with text, an icon, or both, you can create the button in your layout in three ways:

  • With text, using the Button class:
  • With an icon, using the ImageButton class:
  • With text and an icon, using the Button class with the android:drawableLeft attribute:

Key classes are the following:

Responding to Click Events

When the user clicks a button, the Button object receives an on-click event.

To define the click event handler for a button, add the android:onClick attribute to the element in your XML layout. The value for this attribute must be the name of the method you want to call in response to a click event. The Activity hosting the layout must then implement the corresponding method.

For example, here’s a layout with a button using android:onClick :

Within the Activity that hosts this layout, the following method handles the click event:

Kotlin

The method you declare in the android:onClick attribute must have a signature exactly as shown above. Specifically, the method must:

  • Be public
  • Return void
  • Define a View as its only parameter (this will be the View that was clicked)

Using an OnClickListener

You can also declare the click event handler programmatically rather than in an XML layout. This might be necessary if you instantiate the Button at runtime or you need to declare the click behavior in a Fragment subclass.

To declare the event handler programmatically, create an View.OnClickListener object and assign it to the button by calling setOnClickListener(View.OnClickListener) . For example:

Kotlin

Styling Your Button

The appearance of your button (background image and font) may vary from one device to another, because devices by different manufacturers often have different default styles for input controls.

Читайте также:  Android для c 5000

You can control exactly how your controls are styled using a theme that you apply to your entire application. For instance, to ensure that all devices running Android 4.0 and higher use the Holo theme in your app, declare android:theme=»@android:style/Theme.Holo» in your manifest’s element. Also read the blog post, Holo Everywhere for information about using the Holo theme while supporting older devices.

To customize individual buttons with a different background, specify the android:background attribute with a drawable or color resource. Alternatively, you can apply a style for the button, which works in a manner similar to HTML styles to define multiple style properties such as the background, font, size, and others. For more information about applying styles, see Styles and Themes.

Borderless button

One design that can be useful is a «borderless» button. Borderless buttons resemble basic buttons except that they have no borders or background but still change appearance during different states, such as when clicked.

To create a borderless button, apply the borderlessButtonStyle style to the button. For example:

Custom background

If you want to truly redefine the appearance of your button, you can specify a custom background. Instead of supplying a simple bitmap or color, however, your background should be a state list resource that changes appearance depending on the button’s current state.

You can define the state list in an XML file that defines three different images or colors to use for the different button states.

To create a state list drawable for your button background:

    Create three bitmaps for the button background that represent the default, pressed, and focused button states.

To ensure that your images fit buttons of various sizes, create the bitmaps as Nine-patch bitmaps.

Источник

How to Dis­able Mal­func­tion­ing Phys­i­cal But­tons on Android Phones

Abhishek Macwan

19 Mar 2016

Has your phone’s volume button gone mad? I mean does it keep increasing or decreasing the volume on its own? Or has it just got smashed inside the chassis and it won’t stop turning down the volume. Or even worse, your Power button is broken! All of that can be simply fixed by disabling them and using some third-party app to control volume and power on/off. Well, there’s a slight caveat. Your phone should have Root access in order to accomplish this particular task.

Disable hardware buttons that work abnormally | Voyagerix / Shutterstock

Now, if you’ve got a rooted Android phone and would like to disable the physical buttons on your device regardless of them being broken or active, just follow on.

Читайте также:  Apk для android x86

Disable Physical Buttons on Android

So, in order to disable the physical/hardware buttons on Android, you’ll need to edit the root file that enables these buttons. To access these root files you’ll need a File manager that can explore root files. You can use the popular ES File explorer or a specific root explorer like Root Explorer. Or a free root explorer like Root browser. Here, we’ve used ES File explorer to maintain simplicity.

Yes, we know ES File Explore has got quite annoying with some unnecessary add-ons. So, we found some worthy alternatives for it.

Step-1: Open ES File Explorer and Enable Root Explorer. Now tap on Root Explorer to open the options where you got to change the Read and Write options for root files. Tap on Mount R/W and on the next dialog box select write (W) for /system files. So, now we can edit the system OS files.

Step-2: Now under the Local tab in the ES sidebar tap on /Device. This folder contains all the root files. Now, navigate down to this location – system/usr/keylayout. In this folder, you will have Generic.kl and few other files containing the keypad and physical button operation triggers.

Now, here you’ll need to find the perfect file that might work for you. Try out the below given step first in Generic.kl file. If that doesn’t work then use it in some other files that have keywords like Volume_Up, Volume_Down and Power. If you have MediaTek device then you’ll just have to edit mtk-kpd.kl file. As shown in the above screenshot. Follow the below given step carefully.

Step-3: First create a backup of the particular file that you’re going to edit. Here, as I’ve got a MediaTek device so I’ll edit mtk-kpd.kl. To create a backup, create a copy of that file and rename it by adding .bk at the end as an extension.

Now, open the original file and tap on edit. Search for keywords related to Volume_UP, Volume_Down or Power. All you have to do is add # in front of the particular code line for the specific button. Here, I inserted # (with space after it) in front of Volume_Up code key 115.

Step-4: Save the file by hitting the back button and hit Yes. Then, reboot the phone. The specific button on which you added a # won’t function, meaning it’s now disabled.

Basically, what you did here is commented out the code line for that specific button. Anything after # in that specific line won’t be compiled and executed by Android. So, Android is unable to execute the button so the button won’t work now.

Читайте также:  The launcher для андроид

App Solutions for On-screen Functioning of Physical buttons

You have disabled your desired physical button. But only the button is disabled not its function. Any other application can trigger this function (Volume low/high and screen on/off) and use it easily. You can use Pie Control or you can check out this list of apps that will let you control volume on-screen.

Let us know if the above method to disable hardware buttons worked or not. Also, if you have some tips regarding your phone specific to this topic then do share them. You can also ask the question in our forum.

Last updated on 8 Feb, 2018
The above article may contain affiliate links which help support Guiding Tech. However, it does not affect our editorial integrity. The content remains unbiased and authentic.

How To Fix Your Phone Date Is Inaccurate Error In WhatsApp

Is # WhatsApp showing your inaccurate date error on your Phone? Check out these # troubleshooting fixes to resolve the inaccurate date error on # WhatsApp.

4 Best Ways to Turn Off Notifications on Android

Is your phone buzzing because of the # notifications too often? There are different ways to turn off notifications on # Android.

How to Send Group Texts from Android and iPhone

Here’s how to send group # text messages to your family, friends, or offlice colleagues using your # Android and # iPhone.

How to Add and Use Sleep Timer on YouTube Music

Do you miss the sleep # timer functionality on YouTube # Music? if yes, here’s how to add and use sleep # timer on # YouTube Music for both # Android and # iOS.

Top 9 Ways to Fix Facebook Not Loading Pictures

Is # Facebook not loading pictures for you? Let’s troubleshoot the issue on # Android and iPhone.

How to Block and Unblock Someone on Google Hangouts

Top 7 Ways to Fix Google Maps Showing Wrong Location on Android and iOS

# Google Maps showing wrong # location? Check out these # troubleshooting solutions to improve Google # Maps location accuracy on # Android and iPhone.

How to Save Mobile Data While Using Spotify

Want to save up on # mobile data while you enjoy the music on the go? Here’s how to do that.

Did You Know

Google PhotoScan lets you scan your old photos, minus the flash.

Источник

Оцените статью