Set cursor drawable programmatically in android This below method is use for change cursor drawable programmatically in android. Pass two parameter as argument. 1) Object of EditText. 2) Cursor color. private void setCursorDrawableColor(EditText editText, int color) { try { Field fCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes"); fCursorDrawableRes.setAccessible(true); int mCursorDrawableRes = fCursorDrawableRes.getInt(editText); Field fEditor = TextView.class.getDeclaredField("mEditor"); fEditor.setAccessible(true); Object editor = fEditor.get(editText); Class<?> clazz = editor.getClass(); Field fCursorDrawable = clazz.getDeclaredField("mCursorDrawable"); fCursorDrawable.setAccessible(true); Drawable[] drawables = new Drawable[2]; drawables[0] = editText.getConte
Download Code Create custom button in android Maybe you would like to create custom button. We can use custom android buttons for a better layout. Here I’m going to show how to customize Android buttons. In the following image you can see how our buttons will look like. 1) Create button_disable_yellow.xml file in drawable folder. <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <corners android:radius="25dp" /> <solid android:color="#ACAFAF" /> </shape> 2) Create button_enable_yellow.xml file in drawable folder. <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item><layer-list> <item android:right="1dp" android:top="1dp"><shape> <corners android:radius="25dp"
Shared Preferences Tutorial 1) Shared Preferences allow you to save and retrieve data in the form of key,value pair. 2) You cannot share preferences outside of the package. 3) Preferences are stored as groups of key/value pairs. Creating shared preferences SharedPreferences pref = getSharedPreferences(“MyPreferences”, Context.MODE_PRIVATE); - The first parameter is the key and the second parameter is the MODE. - You can save something in the sharedpreferences by using SharedPreferences.Editor class. SharedPreference.Editor editor = pref.edit(); SharedPreferences.Editor Methods : 1) clear() : It will remove all values from the editor. 2) remove(String key) : It will remove the value whose key has been passed as a parameter. 3) putString(String key, String value) : It will save a String value in a preference editor. 4) putLong(String key, long value) : It will save a long value in a preference editor. 5) putInt(String key, int value) : It will save
It's working...
ReplyDelete