- Как отключить кнопку Android?
- How to Disable Malfunctioning Physical Buttons on Android Phones
- Abhishek Macwan
- Disable Physical Buttons on Android
- App Solutions for On-screen Functioning of Physical buttons
- Read Next
- How To Fix Your Phone Date Is Inaccurate Error In WhatsApp
- 4 Best Ways to Turn Off Notifications on Android
- How to Send Group Texts from Android and iPhone
- How to Add and Use Sleep Timer on YouTube Music
- Top 9 Ways to Fix Facebook Not Loading Pictures
- How to Block and Unblock Someone on Google Hangouts
- Top 7 Ways to Fix Google Maps Showing Wrong Location on Android and iOS
- How to Save Mobile Data While Using Spotify
- Did You Know
- How to Disable Volume Buttons on Android
- How to Disable Volume Buttons on Android
- How to Disable Capacitive Buttons on Android
- How to Enable Soft Keys on Android
- How to Remap Buttons (Capacitive and Volume) on Android
Как отключить кнопку Android?
Я создал макет, который содержит две кнопки, Next и Previous. Между кнопками я генерирую некоторые динамические представления. Поэтому, когда я впервые запускаю приложение, я хочу отключить кнопку «Назад», так как предыдущих просмотров не будет. Я также хочу отключить кнопку «Далее», когда больше нет просмотров для отображения. Есть ли вообще отключить кнопки?
Ты пробовал это?
Обновление: спасибо Гвен. Почти забыл, что android:clickable можно установить в макете XML, чтобы определить, можно ли нажимать кнопку или нет.
Вы не можете включить или отключить его в своем XML (так как ваш макет установлен во время выполнения), но вы можете установить, если он активируется при запуске действия с android:clickable .
Вы просто пишете одну строку кода в своей деятельности
Когда вы хотите включить ту же кнопку просто напишите
Да, это можно отключить в XML, просто используя:
В Java, если у вас есть ссылка на кнопку:
Чтобы включить / отключить кнопку, вы можете использовать:
Поскольку вы хотите отключить кнопку с самого начала, вы можете использовать button.setEnabled (false); в методе onCreate. В противном случае из XML вы можете напрямую использовать:
работает нормально и включает и отключает кнопку как надо. Но как только состояние кнопки становится отключенным, оно больше никогда не возвращается в включенное состояние, хотя оно и активируется. Я пытался сделать недействительным и обновить состояние рисования, но безуспешно.
Если у вас или у кого-то возникла похожая проблема, то для меня лучше всего установить фон для рисования. Работает на любом уровне API.
В Kotlin, если вы ссылаетесь на представление кнопок с идентификатором, включите / отключите кнопку как
layout.xml
activity.kt
сначала в xml сделать кнопку как android:clickable=»false»
затем в вашем коде, внутри oncreate() метода установите свойство кнопки как
затем внутри кнопки нажмите изменить код в
НЕПРАВИЛЬНЫЙ СПОСОБ В СЛУШАТЕРЕ ИСПОЛЬЗОВАТЬ ПЕРЕМЕННЫЕ ВМЕСТО ПАРАМЕТРА .
ПРАВИЛЬНО:
РЕДАКТИРОВАТЬ: В ответ на @ jeroen-bollen
является определение интерфейса для обратного вызова , которая будет вызвана , когда вид кнопки.
с определением метода
при щелчке по представлению объект класса View выполняет обратный вызов метода onClick (), отправляя как сам параметр, поэтому нулевой параметр представления не должен появляться, если он является ошибкой утверждения, это может произойти, например, когда класс объекта View был уничтожен за это время (для пример, собранный GC) или метод был подделан из-за взлома
немного о instanceof & null
JLS / 15.20.2. Оператор сравнения типов instanceof
Во время выполнения результат оператора instanceof равен true, если значение RelationalExpression не равно нулю и ссылка может быть приведена к ReferenceType без повышения ClassCastException.
В противном случае результат будет ложным .
три слова от автора
ЕСЛИ ты спрашиваешь, ПОЧЕМУ?
ЧТОБЫ ИЗБЕГАТЬ NullPointerException
Немного больше кода сэкономит ваше время на последующем отслеживании ошибок в вашем коде и уменьшит возникновение аномалий.
рассмотрим следующий пример:
Источник
How to Disable Malfunctioning Physical Buttons 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.
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.
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.
Read Next
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.
Источник
How to Disable Volume Buttons on Android
You’ll see the steps to disable volume and capacitive buttons in this post.
You’ll also see the steps to enable soft keys and remap buttons (capacitive and volume).
Remember that you can do this task on a rooted or non-rooted Android device. Let’s begin.
How to Disable Volume Buttons on Android
Install and open the Buttons remapper (no root) app. Enable the “Accessibility” service for the app (you can follow the on-screen instructions to do this).
You can now see the primary screen. Tap the “+” icon. Choose the “Short and long press” option. Open the drop-down list under “Key” and choose “VOLUME_UP.”
Open the drop-down list under “Action” and select “Do nothing.” Tap the “OK.” Tap the “+” icon. Choose the “Short and long press” option.
Open the drop-down list under “Key” and choose “VOLUME_DOWN.” Open the drop-down list under “Action” and select “Do nothing.” Tap the “OK.”
If you want to enable both the volume buttons, delete both the actions you’ve created. Here’s how you can delete an action:
Long press the action you want to delete and then tap “Delete.”
How to Disable Capacitive Buttons on Android
Install and open the Buttons remapper (no root) app. Enable the “Accessibility” service for the app (you can follow the on-screen instructions to do this).
You can now see the primary screen. Tap the “+” icon. Choose the “Short and long press” option.
Open the drop-down list under “Key” and choose the capacitive button you want to disable. Open the drop-down list under “Action” and select “Do nothing.” Tap the “OK.”
That’s it. The selected capacitive button is disabled. Now, do the above steps (4-6) for all the capacitive buttons you want to disable.
If you want to enable capacitive buttons, then delete the actions you’ve created regarding them. Here’s how you can delete an action:
Long press the action you want to delete and then tap “Delete.”
How to Enable Soft Keys on Android
For Rooted and Non-Rooted Android Devices
Install and open the Simple Control app.
Follow the on-screen instructions to enable the “Allow display over other apps” and “Accessibility” service for the app.
Now you can see the screen. Tap the “OK” button.
Remember, this app has a lot of customization options. Use the ones you prefer.
For Rooted Android Devices
Note: Make a Nandroid backup before proceeding.
Provide “Root” and “Storage” permissions. Now you’re in the “Root Directory.”
Tap system > build.prop file > Text Editor.
Add the following code at the end in a new line: qemu.hw.mainkeys=0
Hit the “Save” icon at the top and tap the “Save & exit” option.
Notes
- To disable the soft keys, remove the code or replace the 0 with the 1 in it.
- If your device has the soft keys by default and you want to disable it, then follow the above steps and replace 0 with 1 in the code.
How to Remap Buttons (Capacitive and Volume) on Android
Enable Accessibility service for the app (you can follow the on-screen instructions).
You can now see the primary screen.
Tap the “+” icon. Choose the “Short and long press” option.
Open the drop-down list under “Key” and choose the capacitive or volume button you want to remap.
Open the drop-down list under “Action” and select your preferred action. Tap the “OK.”
That’s it. Now, do the above steps (4-6) for all the buttons you want to remap.
Remember to swap capacitive buttons or volume buttons using this app.
Let’s see how to swap the volume buttons. For this, you need to create two actions.
Create an action with “VOLUME_UP” from the “Key” drop-down list and “Volume -” from the “Action” drop-down list.
Create an action with “VOLUME_DOWN” from the “Key” drop-down list and “Volume +” from the “Action” drop-down list.
That’s it. From now on, when you press the volume up button, it’ll reduce the volume, and when you press the volume down button, it’ll increase the volume.
Here’s an important thing to remember: if you swap or remap a button, its long-press action won’t work.
If you want to have the long-press action for that button, then you need to create an action for it, and here’s how:
Tap “+” icon. Choose “Short and long press.” Choose that button from the “key” drop-down list and select the long-press action you prefer from the “Action” drop-down list. Choose the “Long press” option. Tap the “OK.”
Here’s another vital thing to note: if you’re creating a long-press action for a button that isn’t swapped or remapped, then the long-press action you create will be added with the existing one. In other words, when you long-press the button, it’ll perform two actions (the action you’ve added and the default one).
Источник