How to display both icon and title of action inside ActionBar?

‘always|withText‘ will work if there is sufficient room, otherwise it will only place icon. You can test it on your phone with rotation. <item android:id=”@id/menu_item” android:title=”text” android:icon=”@drawable/drawable_resource_name” android:showAsAction=”always|withText” />

How to create a number picker dialog?

I have made a small demo of NumberPicker. This may not be perfect but you can use and modify the same. public class MainActivity extends Activity implements NumberPicker.OnValueChangeListener { private static TextView tv; static Dialog d ; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv = (TextView) findViewById(R.id.textView1); Button b = (Button) findViewById(R.id.button11); b.setOnClickListener(new … Read more

How to align LinearLayout at the center of its parent?

These two attributes are commonly confused: android:gravity sets the gravity of the content of the View it’s used on. android:layout_gravity sets the gravity of the View or Layout relative to its parent. So either put android:gravity=”center” on the parent or android:layout_gravity=”center” on the LinearLayout itself. I have caught myself a number of times mixing them … Read more

Show AlertDialog in any position of the screen

After searching in various post I have found the solution. The code is posted below: private CharSequence[] items = {“Set as Ringtone”, “Set as Alarm”}; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { if(item == 0) { } else if(item == 1) { } else if(item == … Read more

Lollipop : draw behind statusBar with its color set to transparent

Method #1: To achieve a completely transparent status bar, you have to use statusBarColor, which is only available on API 21 and above. windowTranslucentStatus is available on API 19 and above, but it adds a tinted background for the status bar. However, setting windowTranslucentStatus does achieve one thing that changing statusBarColor to transparent does not: … Read more

Android basics: running code in the UI thread

None of those are precisely the same, though they will all have the same net effect. The difference between the first and the second is that if you happen to be on the main application thread when executing the code, the first one (runOnUiThread()) will execute the Runnable immediately. The second one (post()) always puts … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)