How did Google manage to do this? Slide ActionBar in Android application

In fact, there’s a way to do this. Even without implementing your own ActionBar. Just have a look at the hierachyviewer! (Located in the tools directory) There’s the DecorView, and a LinearLayout as a child. This LinearLayout contains both the ActionBar and the other content. So, you can simply apply some FrameLayout.LayoutParams to this LinearLayout … Read more

How to create custom button in Android using XML Styles

Copy-pasted from a recipe written by “Adrián Santalla” on androidcookbook.com: https://www.androidcookbook.com/Recipe.seam?recipeId=3307 1. Create an XML file that represents the button states Create an xml into drawable called ‘button.xml’ to name the button states: <?xml version=”1.0″ encoding=”utf-8″?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:state_enabled=”false” android:drawable=”@drawable/button_disabled” /> <item android:state_pressed=”true” android:state_enabled=”true” android:drawable=”@drawable/button_pressed” /> <item android:state_focused=”true” android:state_enabled=”true” android:drawable=”@drawable/button_focused” /> <item android:state_enabled=”true” android:drawable=”@drawable/button_enabled” … Read more

Android Lock Screen Widget

Lock screen interaction is difficult. Android allows basic operations with two window flags (FLAG_SHOW_WHEN_LOCKED and FLAG_DISMISS_KEYGUARD). FLAG_SHOW_WHEN_LOCKED works pretty consistently in that it will show on top of the lock screen even when security is enabled (the security isn’t bypassed, you can’t switch to another non-FLAG_SHOW_WHEN_LOCKED window). If you’re just doing something temporary, like while … Read more

How to control the width and height of the default Alert Dialog in Android?

Only a slight change in Sat Code, set the layout after show() method of AlertDialog. AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(layout); builder.setTitle(“Title”); alertDialog = builder.create(); alertDialog.show(); alertDialog.getWindow().setLayout(600, 400); //Controlling width and height. Or you can do it in my way. alertDialog.show(); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(alertDialog.getWindow().getAttributes()); lp.width = 150; lp.height = 500; lp.x=-170; lp.y=100; … Read more

How to retrieve the dimensions of a view?

I believe the OP is long gone, but in case this answer is able to help future searchers, I thought I’d post a solution that I have found. I have added this code into my onCreate() method: EDITED: 07/05/11 to include code from comments: final TextView tv = (TextView)findViewById(R.id.image_test); ViewTreeObserver vto = tv.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() … Read more

Handling click events on a drawable within an EditText

Actually you don’t need to extend any class. Let’s say I have an EditText editComment with a drawableRight editComment.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { final int DRAWABLE_LEFT = 0; final int DRAWABLE_TOP = 1; final int DRAWABLE_RIGHT = 2; final int DRAWABLE_BOTTOM = 3; if(event.getAction() == MotionEvent.ACTION_UP) { if(event.getRawX() >= … Read more