Skip to main content
To create a Transparent AlertDialog Box:

private void createDialogBox() {

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    final AlertDialog dialog = builder.create();

    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); //hide Title
    getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);  // For FullScreen
    dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);  //Set Transparent BackGround

    View dialogLayout = LayoutInflater.from(getActivity()).inflate(R.layout.demo_dialog, null);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

    dialog.setView(dialogLayout, 0, 0, 0, 0);


    dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface d) {
            .........
            .........
            dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(getResources().getColor(R.color.blue));
       
        }
    });
    dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
    dialog.show();
}

demo_dialog.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout"
    android:width="match_parent"
    android:height="match_parent"
    android:layout_gravity="center"
    android:gravity="center"
    android:onClick="Click"
    android:orientation="vertical"
    android:theme="@style/cust_dialog">

    <ImageView
        android:id="@+id/pullToRefresh_img"
        android:width="match_parent"
        android:height="match_parent"
        android:onClick="Click"
        android:src="@drawable/image1" />

</LinearLayout>

cust_dialog:

<style name="cust_dialog" parent="@android:style/Theme.Holo.NoActionBar.Fullscreen">
    <item name="android:textColor">@color/blue</item>
    <item name="android:background">#80000000</item>
    <item name="android:windowFrame">@null</item>
    <item name="android:windowBackground">@color/black</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowTitleStyle">@null</item>
    <item name="android:colorBackgroundCacheHint">@null</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
    <item name="android:gravity">center</item>
    <item name="colorAccent">#00f3f4f8</item>
</style>

========================
For Changing color of +ve / -ve Button in AlertDialogBox:

        dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface d) {

       dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(getResources ().getColor(R.color.blue));
       }
       });
=========================
Make an AlertDialogBox as Transparent:

dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

=========================

For showing a AlertDailogBox only at first time:

 SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
   boolean dialogShown = settings.getBoolean("dialogShown", false);
   if (!dialogShown) {
     // AlertDialog code here
     SharedPreferences.Editor editor = settings.edit();
     editor.putBoolean("dialogShown", true);
     editor.commit();  
   }

Refer:

http://stackoverflow.com/questions/5409595/how-do-i-show-an-alert-dialog-only-on-the-first-run-of-my-application

=========================



Comments

Popular posts from this blog

SearchView using CursorAdapter

Here  MYFRAGMENT is nothing but name of  a Fragment @Override public void onCreateOptionsMenu (Menu menu, MenuInflater inflater) {     inflater.inflate(R.menu.popup, menu);     final SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);     final SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();     searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));     searchView.setSubmitButtonEnabled(false);     searchView.setIconifiedByDefault(true);     //       searchView.setOnCloseListener(this);     SearchView. OnQueryTextListener textChangeListener = new SearchView. OnQueryTextListener () {         @Override         public boolean onQueryTextSubmit(String query) {             cartAdapt...

Fragment

To enable/disable menu items in Different fragments in same Activity: @Override public void onCreate(@Nullable Bundle savedInstanceState)  {     super.onCreate(savedInstanceState);     setHasOptionsMenu(true);  } @Override public void onPrepareOptionsMenu(Menu menu) {     //Disable the SearchView which is enabled in Product Chart     menu.findItem(R.id.action_search).setVisible(false);   // true to enable } ====================================================

To make a ListView to be scrolled inside of ScrollView

To make a ListView to be scrolled inside of ScrollView: lv . setOnTouchListener ( new ListView . OnTouchListener () { @Override public boolean onTouch ( View v , MotionEvent event ) { int action = event . getAction (); switch ( action ) { case MotionEvent . ACTION_DOWN : // Disallow ScrollView to intercept touch events. v . getParent (). requestDisallowInterceptTouchEvent ( true ); break ; case MotionEvent . ACTION_UP : // Allow ScrollView to intercept touch events. v . getParent (). requestDisallowInterceptTouchEvent ( false ); break ; } // Handle ListView touch events. v . onTouchEvent ( event ); return true ; } }); Refer: http://stackoverflow.com/questions/6210895/listview-inside-scrollview-is-not-scrolling-on-android