I've thought it would be nice if HoloAlertDialogBuilder uses the native AlertDialog.Builder implementation on android API version >= 11, because for now, it uses the custom implementation everywhere, and the blue line under the title on the custom implementation is a little bit larger than on the native ICS implementation.
It would also be usefull if futures android versions change their dialogs' UIs.
I've already written a very small modification for this :
HoloAlertDialogBuilder.java :
package com.WazaBe.HoloEverywhere;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public class HoloAlertDialogBuilder extends AlertDialog.Builder {
private final Context mContext;
private ImageView mIcon;
private TextView mMessage;
private TextView mTitle;
public HoloAlertDialogBuilder(Context context) {
super(context);
mContext = context;
if(Build.VERSION.SDK_INT<11){ //This will make a customdialog only on Android versions < 3.0
// Using the full layout give me a strange top divider in Donut and
// Eclair in when using setView. Using second idea breaks custom View.
Boolean useFullLayout = true;
if (useFullLayout) {
View customTitle = View.inflate(mContext,
R.layout.alert_dialog_title, null);
mTitle = (TextView) customTitle.findViewById(R.id.alertTitle);
FontLoader.loadFont(mTitle, FontLoader.ROBOTO_REGULAR);
mIcon = (ImageView) customTitle.findViewById(R.id.icon);
setCustomTitle(customTitle);
View customMessage = View.inflate(mContext,
R.layout.alert_dialog_message, null);
mMessage = (TextView) customMessage.findViewById(R.id.message);
FontLoader.loadFont(mMessage, FontLoader.ROBOTO_REGULAR);
setView(customMessage);
} else {
View customView = View.inflate(mContext,
R.layout.alert_dialog_holo, null);
mTitle = (TextView) customView.findViewById(R.id.alertTitle);
FontLoader.loadFont(mTitle, FontLoader.ROBOTO_REGULAR);
mIcon = (ImageView) customView.findViewById(R.id.icon);
mMessage = (TextView) customView.findViewById(R.id.message);
FontLoader.loadFont(mMessage, FontLoader.ROBOTO_REGULAR);
setView(customView);
}
}
}
@Override
public HoloAlertDialogBuilder setIcon(Drawable icon) {
if(Build.VERSION.SDK_INT<11){ // On android versions >= 3, this make the call of classic implementation
mIcon.setImageDrawable(icon);
return this;
}else{
return (HoloAlertDialogBuilder) super.setIcon(icon);
}
}
@Override
public HoloAlertDialogBuilder setIcon(int drawableResId) {
if(Build.VERSION.SDK_INT<11){
mIcon.setImageResource(drawableResId);
return this;
}else{
return (HoloAlertDialogBuilder) super.setIcon(drawableResId);
}
}
@Override
public HoloAlertDialogBuilder setMessage(CharSequence text) {
if(Build.VERSION.SDK_INT<11){
mMessage.setText(text);
return this;
}else{
return (HoloAlertDialogBuilder)super.setMessage(text);
}
}
@Override
public HoloAlertDialogBuilder setMessage(int textResId) {
if(Build.VERSION.SDK_INT<11){
mMessage.setText(textResId);
return this;
}else{
return (HoloAlertDialogBuilder)super.setMessage(textResId);
}
}
@Override
public HoloAlertDialogBuilder setTitle(CharSequence text) {
if(Build.VERSION.SDK_INT<11){
mTitle.setText(text);
return this;
}else{
return (HoloAlertDialogBuilder)super.setTitle(text);
}
}
@Override
public HoloAlertDialogBuilder setTitle(int textResId) {
if(Build.VERSION.SDK_INT<11){
mTitle.setText(textResId);
return this;
}else{
return (HoloAlertDialogBuilder)super.setTitle(textResId);
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.WazaBe.HoloEverywhere"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="4" /> <!-- Because the use of Build.VERSION requires minSdkVersion=4 -->
</manifest>
And now, you've got a custom dialog on Android < 3.0 and a native Holo dialog on Android >= 3.0