Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. public class RoundedLinearLayout extends LinearLayout {
  2.  
  3. private Paint drawPaint;
  4. private Paint roundPaint;
  5.  
  6. private int mCornerRadius = 100;
  7.  
  8. private RectF bounds;
  9.  
  10. @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  11. public RoundedLinearLayout(Context context, AttributeSet attrs, int defStyle) {
  12. super(context, attrs, defStyle);
  13. onInit();
  14. }
  15.  
  16. public RoundedLinearLayout(Context context, AttributeSet attrs) {
  17. super(context, attrs);
  18. onInit();
  19. }
  20.  
  21. public RoundedLinearLayout(Context context) {
  22. super(context);
  23. onInit();
  24. }
  25.  
  26. protected void onInit() {
  27. drawPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  28. drawPaint.setColor(0xffffffff);
  29. drawPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
  30.  
  31. roundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  32. roundPaint.setColor(0xffffffff);
  33.  
  34. setWillNotDraw(false);
  35. }
  36.  
  37. @Override
  38. protected void onSizeChanged(int w, int h, int oldw, int oldh) {
  39. super.onSizeChanged(w, h, oldw, oldh);
  40. if (w != oldw && h != oldh) {
  41. bounds = new RectF(0, 0, w, h);
  42. }
  43. }
  44.  
  45. @Override
  46. protected void dispatchDraw(Canvas canvas) {
  47. Bitmap bitmap = Bitmap.createBitmap((int) bounds.width(), (int) bounds.height(), Bitmap.Config.ARGB_8888);
  48. Canvas c = new Canvas(bitmap);
  49. super.dispatchDraw(c);
  50.  
  51. BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
  52.  
  53. Paint paint = new Paint();
  54. paint.setAntiAlias(true);
  55. paint.setShader(shader);
  56.  
  57. canvas.drawRoundRect(bounds, mCornerRadius, mCornerRadius, paint);
  58. }
  59. }
  60.  
  61. LayoutInflater factory = LayoutInflater.from(getActivity());
  62. AlertDialog alert = new AlertDialog.Builder(getActivity());
  63.  
  64. Dialog dialog = new Dialog(getActivity());
  65.  
  66. dialog.setContentView(your layout);
  67.  
  68. dialog.getWindow().setBackgroundDrawable(
  69. new ColorDrawable(android.graphics.Color.TRANSPARENT));
  70.  
  71. myDialog
  72. .getWindow()
  73. .setBackgroundDrawable(new ColorDrawable(Color.argb(0,0,0,0)));
  74.  
  75. <shape xmlns:android="http://schemas.android.com/apk/res/android">
  76. ...
  77. <corners
  78. android:radius="3dp" />
  79. ...
  80. </shape>
  81.  
  82. MyDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
  83.  
  84. Dialog MyDialog= new Dialog(MyActivity.this);
  85. MyDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
  86. MyDialog.setContentView(R.layout.my_custom_dialog);
  87. MyDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
  88. MyDialog.show();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement