I found some code to press home button from code
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
and This one :
moveTaskToBack(true);
I have a activity that is in single task
And a alertDialog with a button then you click on the button one of those code run and go to home
so when you go to app again the alert dismissed before
I want to relaunch the app without dismissing alertDialog
What can i do?
thanks
AlertDialog default button will dissmis dialog .
you should create custom dialog with custom view
public class CustomDialog extends AlertDialog(){
TextView mTitleView,mDescriptionView;
Button mYesButton,mNoButton,mCancelButton;
boolean isYesButtonVisible = true;
boolean isNoButtonVisible = true;
boolean isCancelButtonVisible = true;
public CustomDialog(Context context){
super(context);
}
public void setYesButtonVisible(boolean isVisible){
isYesButtonVisible = isVisible
}
public void setNoButtonVisible(boolean isVisible){
isNoButtonVisible = isVisible
}
public void setCancelButtonVisible(boolean isVisible){
isCancelButtonVisible = isVisible
}
#override
public void show(){
super.show();
setContentView(R.layout.dialog_custom);
mTitleView = findViewById(R.id.text_title);
mDescriptionView = findViewById(R.id.text_description);
mYesButton = findViewById(R.id.btn_yes);
mNoButton = findViewById(R.id.btn_no);
mCancelButton = findViewById(R.id.btn_cancel);
isYesButtonVisible ? mYesButton.setVisibility(View.VISIBLE) : mYesButton.setVisibility(View.GONE);
isNoButtonVisible ? mNoButton.setVisibility(View.VISIBLE) : mNoButton.setVisibility(View.GONE);
isCancelButtonVisible ? mCancelButton.setVisibility(View.VISIBLE) : mCancleButton.setVisibility(View.GONE);
}
//must be called after dialog is showing else you will get NullPointerException
public void setOnYesClickListener(View.OnClickListener listener){
mYesButton.setonClickListener(listener);
}
public void setOnNoClickListener(View.OnClickListener listener){
mNoButton.setonClickListener(listener);
}
public void setOnCancelClickListener(View.OnClickListener listener){
mCancelButton.setonClickListener(listener);
}
}
and layout dialog_custom can be designed by yourself too but this is my layout file for custom dialog
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/text_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/text_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:textSize="16sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/btn_yes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:text="#string/yes"
android:textColor="#color/green_click"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/btn_no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:text="#string/no"
android:textColor="#color/green_click"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#id/btn_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:text="#string/cancel"
android:textColor="#color/green_click"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
While creating AlertDialog with Builder you can set setCancelable(false);.
Related
How to remove the empty space in the dialog. My code-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_horizontal"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/quality_dialog_2x_radio_btn_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/quality_dialog_2x_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2X"
android:textSize="16sp"
android:textColor="#003FBC"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/quality_dialog_1_5x_radio_btn_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/quality_dialog_1_5x_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1.5X"
android:textSize="16sp"
android:textColor="#003FBC"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/quality_dialog_1_point_25_x_radio_btn_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/quality_dialog_1_point_25_x_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1.25X"
android:textSize="16sp"
android:textColor="#003FBC"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/quality_dialog_normal_radio_btn_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/quality_dialog_normal_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Normal"
android:textSize="16sp"
android:textColor="#003FBC"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/quality_dialog_normal_75x_radio_btn_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/quality_dialog_point_75x_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0.75X"
android:textSize="16sp"
android:textColor="#003FBC"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/quality_dialog_5x_radio_btn_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/quality_dialog_point_5x_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0.5X"
android:textSize="16sp"
android:textColor="#003FBC"
android:padding="5dp"/>
</LinearLayout>
</LinearLayout>
My Java Code
View alertLayout = View.inflate(this, R.layout.quality_dialog_layout, null);
TextView quality2XView = alertLayout.findViewById(R.id.quality_dialog_2x_view_id);
TextView quality1_5View = alertLayout.findViewById(R.id.quality_dialog_1_5x_view_id);
TextView quality1_Point25View = alertLayout.findViewById(R.id.quality_dialog_1_point_25_x_view_id);
TextView qualityNormalView = alertLayout.findViewById(R.id.quality_dialog_normal_view_id);
quality_point75View = alertLayout.findViewById(R.id.quality_dialog_point_75x_view_id);
quality_point5View = alertLayout.findViewById(R.id.quality_dialog_point_5x_view_id);
quality2XRadioBtn = alertLayout.findViewById(R.id.quality_dialog_2x_radio_btn_view_id);
quality1_5RadioBtn = alertLayout.findViewById(R.id.quality_dialog_1_5x_radio_btn_view_id);
quality1_Point25RadioBtn = alertLayout.findViewById(R.id.quality_dialog_1_point_25_x_radio_btn_view_id);
qualityNormalRadioBtn = alertLayout.findViewById(R.id.quality_dialog_normal_radio_btn_view_id);
quality_point75RadioBtn = alertLayout.findViewById(R.id.quality_dialog_normal_75x_radio_btn_view_id);
quality_point5RadioBtn = alertLayout.findViewById(R.id.quality_dialog_5x_radio_btn_view_id);
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setView(alertLayout);
alert.setCancelable(true);
qualityAlertDialog = alert.create();
qualityAlertDialog.show();
Suggestion 1:
In order to customize the AlertDialog theme you have to create a new theme for it, which is a bit complicated and quite hard as you have also to create proper images etc.
Regarding this option you can check this topic here
Suggestion 2:
Include the button in the xml:
<Button android:text="OK"
style="?android:attr/borderlessButtonStyle" />
Suggestion 3:
Use the AlertDialog options and don't change the theme, this will add proper spacing in all options and follow the android theming so it will not look strange, but will not remove the spacing you mentioned:
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setSingleChoiceItems(R.array.your_array_options, null/* no item preselected*/,
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// handle the item selection here
}
}
);
alert.setCancelable(true);
qualityAlertDialog = alert.create();
qualityAlertDialog.show();
and the your_array_options will be in a file res/values/array.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array
name="your_array_options">
<item>2X</item>
<item>1.5X</item>
<item>1.25X</item>
...
</string-array>
</resources>
Suggestion 4:
In order to have full customized theme then do not use AlertDialog at all but DialogFragment:
public class MyDialogFragment extends DialogFragment {
// ...
// Empty constructor required for DialogFragment
public MyDialogFragment() {}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.quality_dialog_layout, container);
TextView quality2XView = alertLayout.findViewById(R.id.quality_dialog_2x_view_id);
TextView quality1_5View = alertLayout.findViewById(R.id.quality_dialog_1_5x_view_id);
TextView quality1_Point25View = alertLayout.findViewById(R.id.quality_dialog_1_point_25_x_view_id);
TextView qualityNormalView = alertLayout.findViewById(R.id.quality_dialog_normal_view_id);
quality_point75View = alertLayout.findViewById(R.id.quality_dialog_point_75x_view_id);
quality_point5View = alertLayout.findViewById(R.id.quality_dialog_point_5x_view_id);
quality2XRadioBtn = alertLayout.findViewById(R.id.quality_dialog_2x_radio_btn_view_id);
quality1_5RadioBtn = alertLayout.findViewById(R.id.quality_dialog_1_5x_radio_btn_view_id);
quality1_Point25RadioBtn = alertLayout.findViewById(R.id.quality_dialog_1_point_25_x_radio_btn_view_id);
qualityNormalRadioBtn = alertLayout.findViewById(R.id.quality_dialog_normal_radio_btn_view_id);
quality_point75RadioBtn = alertLayout.findViewById(R.id.quality_dialog_normal_75x_radio_btn_view_id);
quality_point5RadioBtn = alertLayout.findViewById(R.id.quality_dialog_5x_radio_btn_view_id);
// This will also require to add extra buttons in the xml!
// getDialog().setTitle("If you want to change the title");
return view;
}
}
Hey i have a simple question. i have a mobile_navigation that contain code to call a fragment class, and i have the fragment class but i want to call / pass to another java class. for example i have Inputdata.xml that when tap will go to fragment class nah i want when i tap the input xml it will instantly go to another java class not stuck in fragment class
here is the example code for mobile_navigation
<fragment
android:id="#+id/nav_pantuan"
android:name="com.joshua.r0th.crud2.ui.gallery.GalleryFragment"
android:label="#string/pantauan"
tools:layout="#layout/fragment_pantauan" />
and here is the GalleryFragment code
public class GalleryFragment extends Fragment {
private GalleryViewModel GalleryViewModel;
public View onCreateView(#NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
GalleryViewModel =
ViewModelProviders.of(this).get(GalleryViewModel.class);
View root = inflater.inflate(R.layout.fragment_pantauan, container, false);
final TextView textView = root.findViewById(R.id.text_gallery);
GalleryViewModel.getText().observe(this, new Observer<String>() {
#Override
public void onChanged(#Nullable String s) {
textView.setText(s);
}
});
return root;
}
}
and this is the another java class that i willing to reach
public class pantauan extends AppCompatActivity {
database1 myDb;
EditText editNomorRumah,editJentikDalam,editJentikLuar;
Button btnAddData;
Button btnViewAll;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_pantauan);
myDb = new database1(this);
editNomorRumah = (EditText)findViewById(R.id.nomorrmh);
editJentikDalam = (EditText)findViewById(R.id.jentikdirumah);
editJentikLuar = (EditText)findViewById(R.id.jentikdiluarrumah);
btnAddData = (Button)findViewById(R.id.tambahdata);
btnViewAll = (Button)findViewById(R.id.lihatdata);
AddData();
viewAll();
}
//fungsi tambah
public void AddData() {
btnAddData.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
boolean isInserted = myDb.insertData(editNomorRumah.getText().toString(),
editJentikDalam.getText().toString(),
editJentikLuar.getText().toString() );
if(isInserted == true)
Toast.makeText(pantauan.this,"Data Iserted",Toast.LENGTH_LONG).show();
else
Toast.makeText(pantauan.this,"Data Not Iserted",Toast.LENGTH_LONG).show();
}
}
);
}
//fungsi menampilkan data
public void viewAll() {
btnViewAll.setOnClickListener(
new View.OnClickListener(){
#Override
public void onClick(View v) {
Cursor res = myDb.getAllData();
if(res.getCount() == 0) {
// show message
showMessage("Error","Noting Found");
return;
}
StringBuffer buffer = new StringBuffer();
while (res.moveToNext() ) {
buffer.append("NomorRumah :"+ res.getString(0)+"\n");
buffer.append("JentikDalam :"+ res.getString(1)+"\n");
buffer.append("JentikLuar :"+ res.getString(2)+"\n");
}
// show all data
showMessage("Data",buffer.toString());
}
}
);
}
//membuat alert dialog
public void showMessage(String title, String Message){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(Message);
builder.show();
}
}
and here is the Input.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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#drawable/gradient"
android:orientation="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="70dp"
android:background="#drawable/gradient"
android:elevation="4dp"
android:orientation="vertical"
android:padding="20dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="30dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Nomor Rumah" />
<EditText
android:id="#+id/nomorrmh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/roundtext" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Jentik Di Dalam Rumah" />
<EditText
android:id="#+id/jentikdirumah"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/roundtext" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Jentik Di Luar Rumah" />
<EditText
android:id="#+id/jentikdiluarrumah"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/roundtext"
android:layout_marginBottom="10dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="match_parent"
android:layout_gravity="center">
<Button
android:id="#+id/tambahdata"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:background="#d67601"
android:text="Tambah Data"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp" />
<Button
android:id="#+id/lihatdata"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:background="#d67601"
android:text="contoh lihat data"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<TextView
android:id="#+id/textviewadd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="26dp"
android:gravity="center_horizontal"
android:text="Input Data"
android:textColor="#fff"
android:textSize="26sp"
android:textStyle="bold"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<TextView
android:id="#+id/text_gallery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:textAlignment="center"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</RelativeLayout>
My goal is to pass the fragment into the java class that i want, because i dont know how to put that input class to the fragment always get cannot be cast to androidx.fragment.app.Fragment when i replace the GalleryFragment with pantauan.java code. thank you
I have floating button in the FundamentalView.axml
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="22dp"
android:paddingRight="22dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true">
<ImageButton
android:id="#+id/addButton"
android:layout_width="56dp"
android:layout_height="56dp"
android:src="#drawable/ic_add_white_24dp" />
</FrameLayout>
In the FundamentalView.cs, I have click event which triggers a fragment from the bottom of the view with having options (adding a new person and new calculations).
var addButton = view.FindViewById<ImageButton>(Resource.Id.addButton);
addButton.Click += OnAddButtonClick;
void OnAddButtonClick(object sender, System.EventArgs e)
{
var dialog = new CardDialogView();
dialog.Show(((MainView)Activity).SupportFragmentManager, "CardDialogView");
}
CardDialogView.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/dash_add_computer"
android:textColor="#color/primary_text"
android:textSize="16sp"
android:text="New Calculation"
local:MvxBind="Click NewCalculationCommand"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/dash_add_head"
android:drawablePadding="28dp"
android:textColor="#color/primary_text"
android:textSize="16sp"
android:text="New Person" />
</LinearLayout>
My question is how to make TextView clickable and know which textview clicked in mvvmcross?
CardDialogView.cs
public class CardDialogView : MvxDialogFragment<CardDialogViewModel>
{
public override Dialog OnCreateDialog(Bundle savedState)
{
.....
return dialog;
}
}
CardDialogViewModel.cs
public class CardDialogViewModel : MvxViewModel
{
public ICommand NewCalculationCommand
{
get
{
// it does not come here!
return new MvxCommand(() => ShowViewModel<NewItemViewModel>(new { date = DateTime.Now }));
}
}
}
You can bind textview click just like as button click:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/dash_add_computer"
android:textColor="#color/primary_text"
android:textSize="16sp"
local:MvxBind="Click NewCalculationCommand"
android:text="New Calculation" />
For the second textview bind it to another command. This way when the corresponding command is invoked you will know which textview triggered it.
final AlertDialog builder = new AlertDialog.Builder(activity).create();
LayoutInflater factory = LayoutInflater.from(activity);
View view = factory.inflate(R.layout.inventory_item_pop_up, null);
builder.setView(view);
ImageButton discardButton = (ImageButton) view.findViewById(R.id.popup_discard);
discardButton.setClickable(true);
discardButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
listener.remove(f);
builder.dismiss();
}
});
This button click does not respond at all. How can I make this piece of code work?
I use this code in an Adapter, by the way.
the onCLickListener you have registered, is it DialogInterface.OnClickListener? If you have used onCLickListener from View class then that won't work here. Please recheck.
You need to do
discardButton.setOnClickListener(new DialogInterface.OnClickListener() {
#Override
public void onClick(View v) {
listener.remove(f);
builder.dismiss();
}
});
I hope this will helpfull for you. I implement this way for custom Dialog
public void showUpdateDialog() {
updateDialog = new Dialog(this,
android.R.style.Theme_Translucent_NoTitleBar_Fullscreen) {
#Override
public void onBackPressed() {
this.dismiss();
loadDataAsync.execute();
}
};
updateDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
updateDialog.getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
updateDialog.setContentView(R.layout.updatepopup);
logger.info("Network error popup on");
updateDialog.setCancelable(true);
ImageView dialogImage = (ImageView) updateDialog
.findViewById(R.id.dialogheaderimageupdateupdate);
dialogImage.setBackgroundResource(R.drawable.infoimage);
TextView dialogMesage = (TextView) updateDialog
.findViewById(R.id.dialogmessgetextupdate);
TextView currVersion = (TextView) updateDialog
.findViewById(R.id.currentversionupdate);
TextView newVersion = (TextView) updateDialog
.findViewById(R.id.newversionupdate);
TextView dialogHeader = (TextView) updateDialog
.findViewById(R.id.dialogheadertextupdate);
newVersion.setText("Latest version: " + versionCode);
currVersion.setText("Current version : " + currentVersionName);
dialogMesage.setText("Would you like to update now?");
dialogHeader.setText("A program update is available! ");
Button dialogOk = (Button) updateDialog
.findViewById(R.id.dialogokbuttonupdate);
dialogOk.setText("Update");
dialogOk.setFocusable(true);
dialogOk.requestFocus();
dialogOk.setFocusableInTouchMode(true);
dialogOk.requestFocus();
Button dialogCancel = (Button) updateDialog
.findViewById(R.id.dialogcancelbuttonupdate);
dialogOk.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
updateDialog.dismiss();
downLoad = new DownLoad();
downLoad.execute(apkUrl.trim());
}
});
dialogCancel.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
updateDialog.dismiss();
loadDataAsync.execute();
}
});
try {
updateDialog.show();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
And my updatepopup.xml is displayed below
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/layoutsample"
style="#android:style/Theme.Black.NoTitleBar.Fullscreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/dialoghdrbg"
android:orientation="horizontal" >
<ImageView
android:id="#+id/dialogheaderimageupdateupdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/dialogheadertextupdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|right"
android:layout_marginLeft="1dp"
android:gravity="center_vertical|right"
android:textColor="#000000"
android:textSize="25dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/dialogcontentbg"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical" >
<TextView
android:id="#+id/currentversionupdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#ffffff"
android:textSize="23dp"
android:layout_marginTop="10dp"/>
<TextView
android:id="#+id/newversionupdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#ffffff"
android:textSize="23dp" />
<TextView
android:id="#+id/dialogmessgetextupdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#ffffff"
android:textSize="23dp"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_horizontal"
android:layout_marginTop="15dp"
android:gravity="center|center_horizontal"
android:orientation="horizontal" android:layout_marginBottom="10dp">
<Button
android:id="#+id/dialogokbuttonupdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:background="#drawable/buttonanimation"
android:text="#string/OKButton"
android:textSize="20dp"
android:textStyle="bold" />
<Button
android:id="#+id/dialogcancelbuttonupdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:background="#drawable/buttonanimation"
android:text="#string/CancelButton"
android:textSize="20dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Well, this is awkward... The code is correct, I just wasn't calling the right createDialog() method.
I have activity as a dialogue, all the shows I like. But I have a problem with a frame around them. Just like here.
My Activity:
public class AlarmAlert extends Activity implements Alarms.AlarmSettings {
#Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
AlarmAlertWakeLock.acquire(this);
/*
* FIXME Intentionally verbose: always log this until we've fully
* debugged the app failing to start up
*/
Log.v("AlarmAlert.onCreate()");
DigitalClock dc = (DigitalClock) findViewById(R.id.digitalClock1);
mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
Intent i = getIntent();
mAlarmId = i.getIntExtra(Alarms.ID, -1);
Alarms.getAlarm(getContentResolver(), this, mAlarmId);
mKlaxon = new AlarmKlaxon();
mKlaxon.postPlay(this, mAlarmId);
/* Set the title from the passed in label */
setTitleFromIntent(i);
/*
* allow next alarm to trigger while this activity is active
*/
Alarms.disableSnoozeAlert(AlarmAlert.this);
Alarms.disableAlert(AlarmAlert.this, mAlarmId);
Alarms.setNextAlert(this);
mKlaxon.setKillerCallback(new AlarmKlaxon.KillerCallback() {
public void onKilled() {
if (Log.LOGV)
Log.v("onKilled()");
updateSilencedText();
/* don't allow snooze */
mSnoozeButton.setEnabled(false);
dismiss();
mState = KILLED;
}
});
updateLayout();
SharedPreferences settings = getSharedPreferences(
AlarmClock.PREFERENCES, 0);
if (settings.getBoolean(AlarmClock.PREF_SHAKE_SNOOZE, true)) {
mShakeListener = new ShakeListener(this);
mShakeListener
.setOnShakeListener(new ShakeListener.OnShakeListener() {
public void onShake() {
snooze();
if (mCaptchaSnooze == 0)
finish();
}
});
}
}
private void setTitleFromIntent(Intent i) {
mLabel = i.getStringExtra(Alarms.LABEL);
if (mLabel == null || mLabel.length() == 0) {
mLabel = getString(R.string.default_label);
}
setTitle(mLabel);
}
private void updateSilencedText() {
TextView silenced = (TextView) findViewById(R.id.silencedText);
silenced.setText(getString(R.string.alarm_alert_alert_silenced,
mDuration / 1000 * 60));
silenced.setVisibility(View.VISIBLE);
}
private void updateLayout() {
setContentView(R.layout.alarm_alert);
My alert_alarm.xml (Dialog).
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root"
android:layout_width="327dp"
android:layout_height="295dp"
android:background="#drawable/alertbg"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/silencedText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="2dp"
android:paddingTop="2dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/ltgrey"
android:visibility="gone" />
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="230dp"
android:gravity="center_horizontal" >
<Button
android:id="#+id/snooze"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="25dp"
android:layout_marginTop="20dp"
android:background="#drawable/teesstt"
android:text="#string/snooze_button"
android:textColor="#fff"
android:textSize="25dp"
android:visibility="visible" />
<Button
android:id="#+id/dismiss"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="25dp"
android:layout_marginTop="20dp"
android:background="#drawable/teesstt"
android:text="#string/dismiss_button"
android:textColor="#fff"
android:textSize="25dp"
android:visibility="visible" />
</RelativeLayout>
<TextView
android:id="#+id/tvDD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/tvDate"
android:layout_alignLeft="#+id/tvDate"
android:text="Medium Text"
android:textSize="20dp"
android:textColor="#a6a6a6" />
<TextView
android:id="#+id/tvDate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/relativeLayout1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="55dp"
android:layout_marginLeft="30dp"
android:text="Medium Text"
android:textSize="25dp"
android:textColor="#a6a6a6" />
<com.boxclocks.android.alarmclock.dc
android:id="#+id/digitalClock1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="58dp"
android:text="DigitalClock"
android:textColor="#a6a6a6"
android:textSize="70dp" />
</RelativeLayout>
How do I remove the border.
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
Dialog
You have two options. You can set the theme of your Activity to
Theme_Translucent_NoTitleBar
Or you have to create a new theme and load it with a custom nine patch as specified here
How to remove border from Dialog?