Skip to content

Instantly share code, notes, and snippets.

@cristianpalomino
Created July 9, 2015 16:37
Show Gist options
  • Save cristianpalomino/810f8fa9a1cf41511f30 to your computer and use it in GitHub Desktop.
Save cristianpalomino/810f8fa9a1cf41511f30 to your computer and use it in GitHub Desktop.
Crear un Dialogo Personalizado con Bordes redondeados
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="-100%p"
android:toYDelta="0%p"
android:duration="500" />
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="0%p"
android:toYDelta="100%p"
android:duration="500" />
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#ffffff" />
<corners
android:bottomRightRadius="5dp"
android:bottomLeftRadius="5dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp" />
<stroke
android:width="6dp"
android:color="#ffffffff" />
</shape>
package test.cristian.suradialog;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class Main extends ActionBarActivity {
protected Button show;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
show = (Button) findViewById(R.id.show);
show.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SuraDialog suraDialog = new SuraDialog(Main.this);
suraDialog.show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".Main">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Dialog"
android:id="@+id/show"
android:layout_gravity="center" />
</FrameLayout>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name="Dialog_Animation_UP_DOWN">
<item name="android:windowEnterAnimation">@anim/abajo_arriba_b</item>
<item name="android:windowExitAnimation">@anim/arriba_abajo_b</item>
</style>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imgfondo"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:layout_gravity="center" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/corners"
android:layout_gravity="center_horizontal|bottom">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mas Información"
android:textColor="@android:color/white"
android:id="@+id/btnmore"
android:layout_gravity="center_horizontal|bottom" />
</LinearLayout>
<ImageButton
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:id="@+id/imgcerrar"
android:src="@android:drawable/ic_delete"
android:layout_gravity="left|top"
android:layout_marginBottom="5dp"/>
</FrameLayout>
package test.cristian.suradialog;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import com.makeramen.roundedimageview.RoundedTransformationBuilder;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Transformation;
/**
* Created by cristian on 8/07/15.
*/
public class SuraDialog extends AlertDialog {
protected SuraDialog(Context context) {
super(context);
initDialog();
}
protected SuraDialog(Context context, int theme) {
super(context, theme);
initDialog();
}
protected SuraDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
super(context, cancelable, cancelListener);
initDialog();
}
private void initDialog() {
LayoutInflater inflater = LayoutInflater.from(getContext());
final View view = inflater.inflate(R.layout.sura_dialog, null);
setView(view);
ImageView imgfond = (ImageView) view.findViewById(R.id.imgfondo);
Transformation transformation = new RoundedTransformationBuilder()
.cornerRadiusDp(5)
.oval(false)
.build();
Picasso.with(getContext()).
load(R.drawable.fondo)
.transform(transformation)
.into(imgfond);
ImageButton imgcerrar = (ImageButton) view.findViewById(R.id.imgcerrar);
imgcerrar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SuraDialog.this.dismiss();
}
});
getWindow().setWindowAnimations(R.style.Dialog_Animation_UP_DOWN);
getWindow().setBackgroundDrawable(new ColorDrawable(android.R.color.transparent));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment