How to Change programmatically Edittext Cursor Color in android?
Using some reflection did the trick for me Java: XML: Here is a method that you can use that doesn't need an XML:
Technical answers from my Stack Overflow history, with source links and licenses.
Showing 30 of 59 answers tagged java
Exported May 9, 2026
Using some reflection did the trick for me Java: XML: Here is a method that you can use that doesn't need an XML:
RecyclerView is not supported to be used as a RemoteView. See CreatingLayout A RemoteViews object (and, consequently, an App Widget) can support the following layout classes: FrameLayout LinearLayout RelativeLayout...
On many popular devices the market name of the device is not available. For example, on the Samsung Galaxy S6 the value of Build.MODEL could be "SM-G920F" , "SM-G920I" , or "SM-G920W8" . I created a small library that...
Ted's answer to lighten a color wasn't working for me so here is a solution that might help someone else:
Delete the files in onDestroy if isChangingConfigurations() is false or isFinishing is true . Example:
Change to You are using the value from R.color instead of the value you set in your XML.
There isn't a magical tool that will refactor obfuscated code into a buildable project. Most likely, you won't be able to decompile and de-obfuscate an APK to be clean and maintainable code. This is a good thing. There...
Set the user-agent header: Example: Stack Exchange Inbox Reputation and Badges source: https://stackoverflow.com/a/7523425/1048340 Perhaps this is related:...
Using string.indexOf(s) will get the first occurrence. Instead of having a map of keywords and using indexOf you could use a regular expression. I wrote this up real quick as an example: Screenshot of example EditText...
Here is a method to open Settings > Permissions for your application: You should consider using this when your permission is denied and shouldShowRequestPermissionRationale(Activity activity, String permission) returns...
Here is an answer using Jsoup and JSON as dependencies: Output (formatted):
The problem with @ZsoltBoldizsár's answer is that you are using ActionBarActivity . Change getActionBar() to getSupportActionBar() Add the following code in onCreate(Bundle) after you call super.onCreate(Bundle) :...
Check out this section from developer.android.com: In native languages like C++ it's common practice to use getters (i = getCount()) instead of accessing the field directly (i = mCount). This is an excellent habit for...
More info: http://developer.android.com/reference/android/util/Log.html https://developer.android.com/tools/debugging/debugging-log.html Logging libraries: https://android-arsenal.com/tag/57
Here is a class I wrote. You can create your own material color palette or get a random color. Example uses: MaterialColorPalette.java Just copy the class into your project and add the package declaration.
In my testing all IMPL classes had the field "pid". This has worked for me: Just make sure the returned value is not -1. If it is, then parse the output of ps .
This answer is similar to some answers above. However, I feel that it would be beneficial because, unlike other answers, this will remove any extra commas or whitespace and handles abbreviation.
You are calling getResources() before the super.onCreate(Bundle) is called. You must call getResources() after onCreate() . Move your code to onCreate or onStart :
Files in /data are not readable by the shell user. You need to use the run-as command, which will work as long as the debug build is installed. You can check if the file exists: To copy the file to your PC, you will...
There is no public API to do this. You can however use some dirty reflection to create your symbolic link. I just tested the following code and it worked for me: A quick Google search showed this answer if you don't...
As stated in the comments, there are several tools already available to search files in a directory. However, to answer your question, I wrote a simple program that should do what you are looking for:
Possible solution: Testing with your example JSON string: Output: Note: This is not ideal and I just wrote it real quick.
The other answers are correct; you need to check the length of the string before calling str.substring(1) . However, you don't need another method to maintain the ct variable. Here is a Java 101 appropriate answer:
A third-party application does not have permission to set a system property. Therefore, the most likely cause of the crash is that the system is setting the package-name as a value for a system property. Other answers...
The answer from john sakthi does not work correctly if the Bitmap has transparency (PNGs). I modified the answer for correctly getting the red/green/blue averages while accounting for transparent pixels:
Without using a List or Set or any third party library (Java 101 homework ready): Output: Using Set : Using List :
This question reminds me of the discussion in this popular answer from Why is char[] preferred over String for passwords? As noted in comments, it's possible that arrays being moved by the garbage collector will leave...
In AOSP ids normally use underscores. address_id instead of addressId . I have seen attributes use camelCase in AOSP however. That is the best practice. This is from the Code Style Guidelines for Contributors for AOSP:...