I have a custom Dialog, which I inflate and use. Now I wanted to have rounded corners which proves to be rather difficult. And it seems that one of those hacks made it so my Dialog doesn't change size no matter if the width is WrapContent, 10dp, 20dp, 200dp or 300dp. It changes in the layout editor but when I actually launch the app it stays the same.
Editor
InApp
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:background="#drawable/dialog_background"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="Do you want to reset progress?"
android:textColor="#color/black"
android:textSize="18sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/cancel_button"
style="#style/basicButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:backgroundTint="#color/delete_red"
android:padding="10dp"
android:text="Cancel"
android:textColor="#color/white"
android:textSize="20sp" />
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/confirm_button"
style="#style/basicButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Yes"
android:textSize="20sp" />
<nearLayout>
</LinearLayout>nearLayout>
</LinearLayout>
And this is where I build it (note the links in the comments, I think that's what causes the problems, setting the background of the window).
val builder = AlertDialog.Builder(requireContext())
val dialogBinding = ResetProgressDialogBinding.inflate(layoutInflater)
builder.setView(dialogBinding.root)
val dialog = builder.create()
dialog.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)); // https://stackoverflow.com/questions/28937106/how-to-make-custom-dialog-with-rounded-corners-in-android
dialogBinding.root.clipToOutline = true // https://issuetracker.google.com/issues/37036728
And my shape
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#color/white"/>
<corners
android:radius="10dp" />
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp" />
</shape>
I'm using PopupHelper class you can use this code:
public class PopUpHelper {
static Dialog dialog;
public static void showDialog(Activity activity, PINConfirmButtonClickListener action) {
if (dialog != null && dialog.isShowing()) {
boolean isShowing = dialog.isShowing();
return;
}
dialog = new Dialog(activity, R.style.MyAlertDialogStyle);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.(your_dialog_layout);
dialog.setCanceledOnTouchOutside(true);
dialog.setCancelable(true);
dialog.show();
dialog.findViewById(R.id.cancel_button).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
action.onPositiveClicked()
"YOUR_ACTION_HERE"
}
});
dialog.findViewById(R.id.cancel_button).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
action.onNegative()
"YOUR_ACTION_HERE"
}
});
dialog.findViewById(R.id.close_dialog_rl).setOnClickListener(view -> action.onCloseButtonClicked(dialog));
dialog.findViewById(R.id.resend_code_tv).setOnClickListener(view -> action.onResendCodeClicked());
}
public interface TwoButtonClickListener {
void onPositiveClicked(Dialog dialog);
void onNegativeClicked(Dialog dialog);
}
}
MyDialogStyle: (Add to styles.xml)
<!-- Alert Dialog Style-->
<style name="MyAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<!-- Used for the border radius -->
<item name="android:bottomLeftRadius">5dp</item>
<item name="android:bottomRightRadius">5dp</item>
<item name="android:topRightRadius">5dp</item>
<item name="android:topLeftRadius">5dp</item>
<item name="android:autofilledHighlight" tools:targetApi="o">#color/transparent</item>
</style>
and in activity calling Popup :
PopUpHelper.showDialog(this, new PopUpHelper.TwoButtonClickListener() {
#Override
public void onPositiveClicked(Dialog dialog) {
dialog.dismiss();
startHomeActivity();
}
#Override
public void onNegativeClicked(Dialog dialog) {
dialog.dismiss();
}
});
if background transparent not working set "android:background="#android:color/transparent" to dialog layout
Example my layout but you can delete fonts and some fields:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#android:color/transparent"
android:gravity="center"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="12dp">
<androidx.cardview.widget.CardView
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32.5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingHorizontal="25dp"
android:paddingVertical="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="70dp"
android:orientation="vertical"
android:paddingTop="15dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/bold"
android:gravity="center"
android:lineSpacingExtra="4dp"
android:text="#string/add_to_cart"
android:textColor="#color/color_secondary"
android:textSize="18sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:fontFamily="#font/medium"
android:lineSpacingExtra="4dp"
android:gravity="center"
android:text="#string/product_added_to_cart"
android:textColor="#color/color_secondary_60"
android:textSize="14sp"/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="40dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/action_button"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="#color/orange_light"
android:ellipsize="end"
android:fontFamily="#font/medium"
android:foreground="?selectableItemBackground"
android:gravity="center"
android:letterSpacing="0.05"
android:singleLine="true"
android:text="#string/add_to_cart"
android:textColor="#color/white"
android:textSize="16sp"/>
<TextView
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal"
android:id="#+id/cancel_button"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:ellipsize="end"
android:fontFamily="#font/medium"
android:foreground="?selectableItemBackground"
android:gravity="center"
android:letterSpacing="0.05"
android:singleLine="true"
android:text="#string/cancel"
android:textColor="#color/color_secondary_60"
android:textSize="13sp"/>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
<RelativeLayout
android:id="#+id/close_dialog_rl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/card_view"
android:layout_centerHorizontal="true"
android:layout_marginTop="22dp"
android:background="#drawable/shape_circle_white">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerInParent="true"
android:src="#drawable/ic_close"
app:tint="#color/white"/>
</RelativeLayout>
</RelativeLayout>
<ImageView
android:id="#+id/confetti_v"
android:layout_width="65dp"
android:layout_height="65dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#drawable/shape_circle_orange"
android:padding="16dp"
android:src="#drawable/ic_check_white"
app:tint="#color/white"/>
</RelativeLayout>
</LinearLayout>
Related
So basically, I have this DialogFragment that is fullscreen and has a button over a progressbar (if you click the button, it disappears and the progressbar is visible). I initially had the xml in an activity and everything worked as expected there, but now I want to refactor it to a fullscreen dialogfragment.
Problem is, the button that was ontop of the progressbar is now aligned to the bottom of the parentLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_gps_loading"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg_setsensor"
tools:ignore="MissingPrefix"
>
<ImageView
android:layout_width="90dp"
android:layout_height="38dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="45dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:orientation="vertical"
>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:src="#drawable/ic_location"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_marginTop="17dp"
android:gravity="center_horizontal"
android:text="#string/promptGpsPermissionBody"
style="#style/fullscreenText"
/>
</LinearLayout>
<ProgressBar
android:id="#+id/progressBar2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/btnActivateGps"
android:layout_alignTop="#+id/btnActivateGps"
style="?android:attr/progressBarStyle"
/>
<Button
android:id="#+id/btnActivateGps"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="71dp"
android:layout_marginLeft="63dp"
android:layout_marginRight="63dp"
android:background="#color/white"
android:enabled="true"
android:visibility="visible"
/>
</RelativeLayout>
What's especially weird is that the progressbar is aligned to the button, but it's still located at the same position as before
here is the java-code
public class GpsSensorDialog extends DialogFragment {
#NonNull #Override public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.activity_gps_sensor, null);
builder.setView(view);
Dialog dialog = builder.create();
if (dialog.getWindow() != null) {
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.getWindow()
.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
}
return dialog;
}
#Override public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NO_TITLE, R.style.CustomDialog);
}
public static GpsSensorDialog newInstance() {
Bundle args = new Bundle();
GpsSensorDialog fragment = new GpsSensorDialog();
fragment.setArguments(args);
return fragment;
}
#Override public void onStart() {
super.onStart();
getDialog().getWindow()
.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
}
}
and the Style I set in onCreate
<style name="CustomDialog">
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
</style>
Try this layout. Also, change your drawables, style and strings accordingly.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_gps_loading"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#mipmap/ic_launcher"
tools:ignore="MissingPrefix">
<ImageView
android:layout_width="90dp"
android:layout_height="38dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="45dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:orientation="vertical">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:src="#mipmap/ic_launcher" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_marginTop="17dp"
android:gravity="center_horizontal"
android:text="obsdas" />
</LinearLayout>
<ProgressBar
android:id="#+id/progressBar2"
style="?android:attr/progressBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/btnActivateGps" />
<Button
android:id="#+id/btnActivateGps"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_marginBottom="71dp"
android:layout_marginLeft="63dp"
android:layout_marginRight="63dp"
android:background="#android:color/white"
android:enabled="true"
android:visibility="visible" />
</RelativeLayout>
I want to make my alert dialog box something like this.This is a popup window where you have to choose and select the category.Its coming when I click any listview item..
But I ended up make it something like this.as i am a newbie so don't know much about designing.kindly help me in this.
my xml layout:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#FFFFFF"
android:gravity="start"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="#+id/desimage"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:layout_marginRight="2dp"
android:layout_marginTop="10dp"
android:src="#drawable/logo" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_weight="1" >
<TextView
android:text="Chicken Pizza Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="21sp"
android:textStyle="bold"
android:id="#+id/h1"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_weight="1" >
<TextView
android:text="Chicken Pizza Small Combo"
android:layout_width="wrap_content"
android:textSize="16sp"
android:layout_height="wrap_content"
android:textColor="#8c8181"
android:id="#+id/h2"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_weight="1" >
<Button
android:text="Quantity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/mybutton"
android:textColor="#ffffff"
android:id="#+id/quant"
android:layout_weight="1" />
<Button
android:text="-"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/incr"
android:textSize="10sp"
android:textColor="#color/colorButton"
android:layout_weight="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:layout_weight="1"
android:id="#+id/n1"
/>
<Button
android:text="+"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10sp"
android:textColor="#color/colorButton"
android:layout_weight="1" />
android:id="#+id/decr"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_weight="1" >
<CheckBox
android:text="SL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/sl"
android:textColor="#8c8181"
android:layout_weight="1" />
<CheckBox
android:text="S"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/s"
android:textColor="#8c8181"
android:layout_weight="1" />
<CheckBox
android:text="M"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/m"
android:textColor="#8c8181"
android:layout_weight="1" />
<CheckBox
android:text="l"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/L"
android:textColor="#8c8181"
android:layout_weight="1" />
<CheckBox
android:text="F"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/f"
android:textColor="#8c8181"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_weight="1" >
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#c0c0c0"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_weight="1" >
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner1"
android:background="#drawable/spinner_bg"
android:layout_weight="1" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner2"
android:background="#drawable/spinner_bg"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_weight="1" >
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView2"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_weight="1" >
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="hint" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_weight="1" >
<Button
android:text="Cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/canc"
android:textColor="#ffffff"
android:background="#drawable/mybutton2"
android:layout_weight=".5" />
<Button
android:text="Ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ok"
android:textColor="#ffffff"
android:background="#drawable/mybutton"
android:layout_weight=".5" />
</LinearLayout>
</LinearLayout>
</ScrollView>
here is my SubMenu Activity where if u click an item it will show popup
public class SubMenu extends AppCompatActivity {
JSONObject jsonobject;
JSONArray jsonarray;
ListView listview;
ListViewAdapter adapter;
ProgressDialog mProgressDialog;
ArrayList<HashMap<String, String>> arraylist;
static String RANK = "id";
static String COUNTRY = "name";
static String FLAG = "image";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sub_menu);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
String SelectedId = getIntent().getStringExtra("id");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// Get the view from listview_main.xml
// Execute DownloadJSON AsyncTask
new DownloadJSON().execute();
}
// DownloadJSON AsyncTask
private class DownloadJSON extends AsyncTask<Void, Void, Void> implements AdapterView.OnItemClickListener {
// #Override
// protected void onPreExecute() {
// super.onPreExecute();
// Create a progressdialog
// mProgressDialog = new ProgressDialog(SubMenu.this);
// Set progressdialog title
// mProgressDialog.setTitle("Categories of Main categories.....");
// Set progressdialog message
// mProgressDialog.setMessage("Loading...");
// mProgressDialog.setIndeterminate(false);
// Show progressdialog
// mProgressDialog.show();
// }
#Override
protected Void doInBackground(Void... params) {
// Create an array
arraylist = new ArrayList<HashMap<String, String>>();
// Retrieve JSON Objects from the given URL address
jsonarray = JsonFunctions
.getJSONfromURL("http://cloud.granddubai.com/broccoli/menu_typeitem.php?id=" + getIntent().getStringExtra("id"));
try {
// Locate the array name in JSON
// jsonarray = jsonobject.getJSONArray("main_menu_items");
for (int i = 0; i < jsonarray.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
jsonobject = jsonarray.getJSONObject(i);
// Retrive JSON Objects
// map.put("id", jsonobject.getString("id"));
map.put("name", jsonobject.getString("name"));
map.put("image", jsonobject.getString("image"));
// Set the JSON Objects into the array
arraylist.add(map);
}
} catch (JSONException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Void args) {
// Locate the listview in listview_main.xml
listview = (ListView) findViewById(R.id.list1);
// Pass the results into ListViewAdapter.java
adapter = new ListViewAdapter(SubMenu.this, arraylist);
// Set the adapter to the ListView
listview.setAdapter(adapter);
listview.setOnItemClickListener(this);
// Close the progressdialog
// mProgressDialog.dismiss();
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
LayoutInflater layoutInflater
= (LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
Button btnDismiss = (Button)popupView.findViewById(R.id.canc);
btnDismiss.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
popupWindow.dismiss();
}});
popupWindow.showAsDropDown(view, 3000, -90);
}
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
Replace your layout xml file with this:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<ImageView
android:id="#+id/desimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/logo" />
<TextView
android:id="#+id/h1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Chicken Pizza Small"
android:textSize="21sp"
android:textStyle="bold" />
<TextView
android:id="#+id/h2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Chicken Pizza Small Combo"
android:textColor="#8c8181"
android:textSize="16sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:weightSum="10">
<Button
android:id="#+id/quant"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="10dp"
android:layout_weight="3"
android:background="#drawable/mybutton"
android:text="Quantity"
android:textAllCaps="false"
android:textColor="#ffffff" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="7"
android:background="#drawable/stroke_button"
android:orientation="horizontal"
android:weightSum="3">
<Button
android:id="#+id/incr"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#android:color/transparent"
android:text="-"
android:textColor="#FFA726"
android:textSize="25dp" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#c0c0c0" />
<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:inputType="number"
android:text="5" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#c0c0c0" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#android:color/transparent"
android:text="+"
android:textColor="#FFA726"
android:textSize="25dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<CheckBox
android:id="#+id/sl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:buttonTint="#c0c0c0"
android:text="SL"
android:textColor="#8c8181"
tools:targetApi="lollipop" />
<CheckBox
android:id="#+id/s"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:buttonTint="#c0c0c0"
android:text="S"
android:textColor="#8c8181"
tools:targetApi="lollipop" />
<CheckBox
android:id="#+id/m"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:buttonTint="#c0c0c0"
android:text="M"
android:textColor="#8c8181"
tools:targetApi="lollipop" />
<CheckBox
android:id="#+id/L"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:buttonTint="#c0c0c0"
android:text="l"
android:textColor="#8c8181"
tools:targetApi="lollipop" />
<CheckBox
android:id="#+id/f"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:buttonTint="#c0c0c0"
android:text="F"
android:textColor="#8c8181"
tools:targetApi="lollipop" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#c0c0c0" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:background="#drawable/stroke_button"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingTop="5dp">
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:background="#drawable/stroke_button"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingTop="5dp">
<Spinner
android:id="#+id/spinner2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp" />
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="SPECIAL INSTRUCTIONS"
android:textSize="16sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#drawable/stroke_button"
android:padding="#dimen/_10sdp">
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:gravity="top"
android:inputType="textCapSentences|textMultiLine"
android:lines="5"
android:maxLines="5"
android:padding="2dp"
android:textColor="#c0c0c0" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp">
<Button
android:id="#+id/canc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:background="#drawable/mybutton2"
android:text="Cancel"
android:textColor="#ffffff" />
<Button
android:id="#+id/ok"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:background="#drawable/mybutton"
android:text="Ok"
android:textColor="#ffffff" />
</LinearLayout>
</LinearLayout>
</ScrollView>
In your res/drawable add these xml:
mybutton.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="25dp" />
<solid android:color="#004D40" />
</shape>
mybutton2.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="25dp" />
<solid android:color="#FFA726" />
</shape>
stroke_button.xml
<?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:radius="20dp" />
<stroke
android:width="1dp"
android:color="#c0c0c0" />
</shape>
#z.al
1) For set quantity u remove two button instead of two button you simply put two TextView so now you have Total 3 TextView (One for "-" one for "Count" and one for "+"). This Textview have Linear as parent and with the help of Drawable XML u can set Background.
2) And for Spinner you need to implement Custom Spinner
for Proper view give proper padding and margin.
refer link for custom spinner: "http://mrbool.com/how-to-customize-spinner-in-android/28286"
I'm trying to create a fullscreen (but status bar has to still be visible) Dialog with custom transparent (same as this answer https://stackoverflow.com/a/29482234), but my background is not transparent.
I've wasted 2 days trying all solution, but it just won't work. My goal is to show a dialog with custom dim color (instead of default black). The answer above looked like what I needed but I can't get it to work. Any suggestions?
My code:
<style name="CustomDialogTheme2" parent="#android:style/Theme.Dialog">
<item name="android:windowIsFloating">false</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
</style>
Layout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#AAFFFFFF">
<RelativeLayout
android:id="#+id/dialog_root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="#CCFF0000"
android:padding="16dp">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</RelativeLayout>
</FrameLayout>
DialogFragment:
public class TestDialogFrag extends DialogFragment {
public static TestDialogFrag newInstance() {
Bundle args = new Bundle();
TestDialogFrag fragment = new TestDialogFrag();
fragment.setArguments(args);
return fragment;
}
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.CustomDialogTheme2);
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.test_dialog_frag, container, false);
return view;
}
}
Try the below, It will help you.
Layout File
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center">
<LinearLayout
android:layout_width="260dp"
android:layout_height="wrap_content"
android:background="#color/colorWhite"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="72dp"
android:layout_gravity="center"
android:gravity="center">
<ImageView
android:id="#+id/dialog_universal_info_image"
android:layout_width="match_parent"
android:layout_height="72dp"
android:background="#ff0000"
android:contentDescription="Imagg"
android:scaleType="centerCrop" />
<View
android:layout_width="match_parent"
android:layout_height="72dp"
android:background="#4cbdbcbc" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/app_name"
android:textColor="#android:color/white"
android:textAppearance="?android:textAppearanceLarge" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="22dp"
android:paddingLeft="26dp"
android:paddingRight="26dp"
android:paddingTop="22dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/dialog_info_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:text="heare"
android:textColor="#android:color/holo_green_dark"
android:textAppearance="?android:textAppearanceLarge" />
<TextView
android:id="#+id/dialog_info_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="4"
android:text="Content is here"
android:textColor="#android:color/holo_green_dark" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="22dp"
android:layout_marginRight="22dp"
android:background="#android:color/holo_blue_dark" />
<TextView
android:id="#+id/dialog_info_ok"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="OK"
android:textColor="#android:color/holo_green_dark"
android:textSize="14sp" />
</LinearLayout>
</RelativeLayout>
Java File
public class DialogUtilsInfo {
public Activity mDialogUniversalInfoActivity;
private Dialog mDialog;
private TextView mDiaappicon_48KButton;
public DialogUtilsInfo(Activity mDialogUniversalActivity) {
this.mDialogUniversalInfoActivity = mDialogUniversalActivity;
}
public void showDialog(String content) {
if (mDialog == null) {
mDialog = new Dialog(mDialogUniversalInfoActivity, R.style.CustomDialogTheme);
}
mDialog.setContentView(R.layout.dialog_info);
mDialog.setCancelable(true);
mDialog.show();
mDiaappicon_48KButton = (TextView) mDialog.findViewById(R.id.dialog_info_ok);
initDialogButtons1();
}
private void initDialogButtons1() {
mDiaappicon_48KButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
mDialog.dismiss();
}
});
}
public void dismissDialog() {
mDialog.dismiss();
}
}
How to generate custom dialog box in android like this,
I want just like this.
How to generate it. please give me suggestion.
i have used below code for dialog box, what is the problem in my code?
I have not identify it. please share me any Idea.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent">
<RelativeLayout
android:id="#+id/rl_quit_learning"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#drawable/btn_white"
android:paddingBottom="#dimen/thirty_dp"
android:paddingLeft="#dimen/ten_dp"
android:paddingRight="#dimen/ten_dp"
android:paddingTop="#dimen/ten_dp">
<TextView
android:id="#+id/tv_quit_learning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_margin="#dimen/ten_dp"
android:text="Quit LEarning?"
android:textSize="#dimen/twenty_sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_quit_learning"
android:layout_centerHorizontal="true"
android:layout_marginLeft="#dimen/ten_dp"
android:layout_marginRight="#dimen/ten_dp"
android:layout_marginTop="#dimen/twenty_dp"
android:gravity="center"
android:text="You are 400pts. away from \n unlocking rewards. Quit LEarning?"
android:textSize="#dimen/sixteen_sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="125dp"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="#+id/btn_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel" />
<Button
android:id="#+id/btn_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Video" />
</LinearLayout>
</RelativeLayout>
Please share me any Idea.
Thanks.
Simple, 1st need to create an newcustom_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_gravity="center"
android:layout_marginLeft="55dp"
android:layout_marginRight="55dp"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="165dp"
android:layout_gravity="center"
android:layout_marginEnd="60dp"
android:layout_marginStart="60dp"
app:cardCornerRadius="8dp"
app:cardElevation="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="14dp"
android:gravity="center"
android:text="Quit Earning?"
android:textColor="#android:color/black"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="20dp"
android:layout_marginStart="20dp"
android:gravity="center"
android:text="You are 400pts. away from \n unlocking rewards. quit Earning?"
android:textSize="18dp"
android:textStyle="bold" />
</android.support.v7.widget.CardView>
</LinearLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/frmNo"
android:layout_marginRight="45dp"
android:layout_marginTop="75dp">
<android.support.design.widget.FloatingActionButton
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#android:color/transparent"
app:backgroundTint="#color/fab2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:elevation="6dp"
android:text="No"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/white"
android:textStyle="bold" />
</FrameLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/frmOk"
android:layout_marginLeft="50dp"
android:layout_marginTop="75dp">
<android.support.design.widget.FloatingActionButton
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#android:color/transparent"
app:backgroundTint="#color/fab1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:elevation="6dp"
android:text="Ok"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/white"
android:textStyle="bold" />
</FrameLayout>
</FrameLayout>
Then, in java file (in activity) paste this code
public class ViewDialog {
public void showDialog(Activity activity) {
final Dialog dialog = new Dialog(activity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(false);
dialog.setContentView(R.layout.newcustom_layout);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
FrameLayout mDialogNo = dialog.findViewById(R.id.frmNo);
mDialogNo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"Cancel" ,Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
FrameLayout mDialogOk = dialog.findViewById(R.id.frmOk);
mDialogOk.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"Okay" ,Toast.LENGTH_SHORT).show();
dialog.cancel();
}
});
dialog.show();
}
}
Finally you can call it wherever you want.
ViewDialog alert = new ViewDialog();
alert.showDialog(CustomDialogActivity.this);
Inside your dailog.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white">
<RelativeLayout
android:id="#+id/rl_quit_learning"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#drawable/btn_white"
android:paddingBottom="#dimen/thirty_dp"
android:paddingLeft="#dimen/ten_dp"
android:paddingRight="#dimen/ten_dp"
android:paddingTop="#dimen/ten_dp">
<TextView
android:id="#+id/tv_quit_learning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_margin="#dimen/ten_dp"
android:text="Quit LEarning?"
android:textSize="#dimen/twenty_sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_quit_learning"
android:layout_centerHorizontal="true"
android:layout_marginLeft="#dimen/ten_dp"
android:layout_marginRight="#dimen/ten_dp"
android:layout_marginTop="#dimen/twenty_dp"
android:gravity="center"
android:text="You are 400pts. away from \n unlocking rewards. Quit LEarning?"
android:textSize="#dimen/sixteen_sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="125dp"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="#+id/btn_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#mipmap/ic_launcher" />
<Button
android:id="#+id/btn_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#mipmap/ic_launcher" />
</LinearLayout>
</RelativeLayout>
open dimens.xml and add code mentioned below
<dimen name="thirty_dp">30dp</dimen>
<dimen name="ten_dp">10dp</dimen>
<dimen name="twenty_sp">20sp</dimen>
<dimen name="twenty_dp">20dp</dimen>
<dimen name="sixteen_sp">16sp</dimen>
open drawable and create btn_white.xml add code mentioned blow
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="2dp"></corners>
<solid android:color="#android:color/white"></solid>
</shape>
open mainactivity.java and add the code mentioned below
final Dialog dialog = new Dialog(MainActivity.this);
// Include dialog.xml file
dialog.setContentView(R.layout.dailog);
dialog.show();
Button declineButton = (Button) dialog.findViewById(R.id.btn_cancel);
// if decline button is clicked, close the custom dialog
declineButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Close dialog
dialog.dismiss();
}
});
Button videoButton = (Button) dialog.findViewById(R.id.btn_video);
// if decline button is clicked, close the custom dialog
videoButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
custom_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:background="#3E80B4"
android:orientation="vertical" >
<TextView
android:id="#+id/txt_dia"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:text="Do you realy want to exit ?"
android:textColor="#android:color/white"
android:textSize="15dp"
android:textStyle="bold"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#3E80B4"
android:orientation="horizontal" >
<Button
android:id="#+id/btn_yes"
android:layout_width="100dp"
android:layout_height="30dp"
android:background="#android:color/white"
android:clickable="true"
android:text="Yes"
android:textColor="#5DBCD2"
android:textStyle="bold" />
<Button
android:id="#+id/btn_no"
android:layout_width="100dp"
android:layout_height="30dp"
android:layout_marginLeft="5dp"
android:background="#android:color/white"
android:clickable="true"
android:text="No"
android:textColor="#5DBCD2"
android:textStyle="bold" />
</LinearLayout>
You can change your button by using
android:src=#drawable/image
You have to extends Dialog and implements OnClickListener
public class CustomDialogClass extends Dialog implements
android.view.View.OnClickListener {
public Activity c;
public Dialog d;
public Button yes, no;
public CustomDialogClass(Activity a) {
super(a);
// TODO Auto-generated constructor stub
this.c = a;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.custom_dialog);
yes = (Button) findViewById(R.id.btn_yes);
no = (Button) findViewById(R.id.btn_no);
yes.setOnClickListener(this);
no.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_yes:
c.finish();
break;
case R.id.btn_no:
dismiss();
break;
default:
break;
}
dismiss();
}
}
Call Dialog
CustomDialogClass cdd=new CustomDialogClass(Activity.this);
cdd.show();
Maybe try this method
dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardBackgroundColor="#color/colorPrimary"
app:cardCornerRadius="16dp"
app:cardElevation="10dp"
app:contentPadding="20dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_done_all"
android:layout_gravity="center_horizontal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/colorButtonNormal"
android:text="Tebrikler!"
android:layout_gravity="center_horizontal"
android:textSize="36sp"
android:padding="8dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/btnDialogCancel"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Çıkış"
android:textColor="#FFF"
android:layout_marginRight="5dp"
android:background="#drawable/dialog_button_background"
android:layout_gravity="center_horizontal"/>
<Button
android:id="#+id/btnDialogOk"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Devam"
android:textColor="#FFF"
android:layout_marginLeft="5dp"
android:background="#drawable/dialog_button_background"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
main.java
Dialog dialog = new Dialog(context, R.style.CustomDialog);
LayoutInflater layoutInflater = LayoutInflater.from(context);
CardView cardView = (CardView) layoutInflater.inflate(R.layout.dialog, null);
dialog.setContentView(cardView);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
dialogBtnCancel();
private void dialogBtnCancel(){
mBtnDialogCancel = dialog.findViewById(R.id.btnDialogCancel);
mBtnDialogOk = dialog.findViewById(R.id.btnDialogOk);
mBtnDialogCancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
dialog.dismiss();
}
});
mBtnDialogOk.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(getActivity(), MainActivity.class);
startActivity(intent);
}
});
}
I have DialogFragment, which show some information. It's work nice, but I need different header, I need white Title color text and blue background of the header.
This is my xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher"
android:id="#+id/icon_teacher"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/teacher"
android:id="#+id/teacher"
android:layout_marginLeft="10dp"
android:layout_alignTop="#+id/icon_teacher"
android:layout_toRightOf="#+id/icon_teacher"
android:layout_toEndOf="#+id/icon_teacher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name_of_teacher"
android:textColor="#android:color/black"
android:textSize="16dp"
android:id="#+id/teacher_name"
android:layout_below="#+id/teacher"
android:layout_alignLeft="#+id/teacher"
android:layout_alignStart="#+id/teacher" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher"
android:id="#+id/icon_time"
android:layout_below="#+id/icon_teacher"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/teacher"
android:id="#+id/time"
android:layout_marginLeft="10dp"
android:layout_alignTop="#+id/icon_time"
android:layout_toRightOf="#+id/icon_time"
android:layout_toEndOf="#+id/icon_time" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name_of_teacher"
android:textColor="#android:color/black"
android:textSize="16dp"
android:id="#+id/time_name"
android:layout_below="#+id/time"
android:layout_alignLeft="#+id/time"
android:layout_alignStart="#+id/time" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher"
android:id="#+id/icon_place"
android:layout_below="#+id/icon_time"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/teacher"
android:id="#+id/place"
android:layout_marginLeft="10dp"
android:layout_alignTop="#+id/icon_place"
android:layout_toRightOf="#+id/icon_place"
android:layout_toEndOf="#+id/icon_place" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name_of_teacher"
android:textColor="#android:color/black"
android:textSize="16dp"
android:id="#+id/place_name"
android:layout_below="#+id/place"
android:layout_alignLeft="#+id/place"
android:layout_alignStart="#+id/place" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher"
android:id="#+id/icon_home"
android:layout_below="#+id/icon_place"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/teacher"
android:id="#+id/home"
android:layout_marginLeft="10dp"
android:layout_alignTop="#+id/icon_home"
android:layout_toRightOf="#+id/icon_home"
android:layout_toEndOf="#+id/icon_home" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name_of_teacher"
android:textColor="#android:color/black"
android:textSize="16dp"
android:id="#+id/place_home"
android:layout_below="#+id/home"
android:layout_alignLeft="#+id/home"
android:layout_alignStart="#+id/home" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:id="#+id/divider1"
android:layout_below="#+id/icon_home"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/divider1"
android:layout_marginTop="10dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher"
android:layout_marginLeft="10dp"
android:id="#+id/imageView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/alert"
android:id="#+id/alert"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical"/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
And my DialogFragment, but i think it won't be helpful so much:
public class LessonDialogFragment extends DialogFragment {
View view;
String title;
public LessonDialogFragment(String title) {
this.title = title;
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.detail_dialog_fragment, container, false);
getDialog().setTitle(title);
return view;
}
}
I don't know how change it, maybe you can help me.
for custom layout:
https://developer.android.com/guide/topics/ui/dialogs.html#CustomLayout
AlertDialog dialog = builder.show();
// Set title divider color
int titleDividerId = getResources().getIdentifier("titleDivider", "id", "android");
View titleDivider = dialog.findViewById(titleDividerId);
if (titleDivider != null)
titleDivider.setBackgroundColor(getResources().getColor(android.R.color.holo_purple));
Customising the background of the header is slightly more complex... You need to define in your theme an alertDialogStyle defining how you draw each area of the dialog. For example:
<style name="Theme.Yours" parent="#android:style/Theme.Holo">
...
<item name="android:alertDialogStyle">#style/AlertDialog_Yours</item>
</style>
<style name="AlertDialog_Yours">
<item name="android:fullDark">...</item>
<item name="android:topDark">...</item>
<item name="android:centerDark">...</item>
<item name="android:bottomDark">...</item>
<item name="android:fullBright">...</item>
<item name="android:topBright">...</item>
<item name="android:centerBright">...</item>
<item name="android:bottomBright">...</item>
<item name="android:bottomMedium">...</item>
<item name="android:centerMedium">...</item>
</style>