Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从android的自定义活动中删除底部工作表对话_Android_Android Layout_Android Fragments_Android Dialog - Fatal编程技术网

从android的自定义活动中删除底部工作表对话

从android的自定义活动中删除底部工作表对话,android,android-layout,android-fragments,android-dialog,Android,Android Layout,Android Fragments,Android Dialog,在Chintan Khetiya的回答的帮助下,我创建了一个定制的底层android对话: 我想从BottomDialogue自己的活动中定义的按钮中取消对话,而不是从调用活动中取消对话 以下是我在调用活动中的代码,在调用活动中,我通过单击按钮创建了我的自定义底部工作表\u liab实例: openBottomDialogeButton.setOnClickListener(new View.OnClickListener() { @Override

在Chintan Khetiya的回答的帮助下,我创建了一个定制的底层android对话:

我想从BottomDialogue自己的活动中定义的按钮中取消对话,而不是从调用活动中取消对话

以下是我在调用活动中的代码,在调用活动中,我通过单击按钮创建了我的自定义底部工作表\u liab实例:

openBottomDialogeButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                   **//Creating the BottomDialogue Instance**`Bottomsheet_liab dialog;
    dialog=new Bottomsheet_liab(getActivity());
dialog.getWindow().setBackgroundDrawable(newColorDrawable(Color.TRANSPARENT));`

        }
    });
以下是我在对话活动中的代码:

public class Bottomsheet_liab extends BottomSheetDialog{
@Override
 protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.cashflow_bottomsheet);
         Button btn=(Button)findViewByID(R.id.btnx);
         btn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                   **//I want to dismiss this BottomSheetDialogue from here.How can I do this>**
        }
    });

}

尝试此方法,您需要调用
discouse()方法,如下面的代码

btn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
      dismiss();
    }
});
示例代码

public class Bottomsheet_liab extends BottomSheetDialog{
@Override
 protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.cashflow_bottomsheet);
         Button btn=(Button)findViewByID(R.id.btnx);
         btn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                   dismiss();
        }
    });

}
private Button startbtn, okaybtn, cancelbtn;
BottomSheetDialog mBottomSheetDialog;
View sheetView;

    mBottomSheetDialog = new BottomSheetDialog(HomeActivity.this);
    sheetView = getLayoutInflater().inflate(R.layout.botomdialouge,null);
    mBottomSheetDialog.setContentView(sheetView);


    okaybtn = sheetView.findViewById(R.id.okaybtn);
    cancelbtn = sheetView.findViewById(R.id.cancelbtn);

   okaybtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });

    cancelbtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mBottomSheetDialog.dismiss();
        }
    });

尝试以下代码

public class Bottomsheet_liab extends BottomSheetDialog{
@Override
 protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.cashflow_bottomsheet);
         Button btn=(Button)findViewByID(R.id.btnx);
         btn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                   dismiss();
        }
    });

}
private Button startbtn, okaybtn, cancelbtn;
BottomSheetDialog mBottomSheetDialog;
View sheetView;

    mBottomSheetDialog = new BottomSheetDialog(HomeActivity.this);
    sheetView = getLayoutInflater().inflate(R.layout.botomdialouge,null);
    mBottomSheetDialog.setContentView(sheetView);


    okaybtn = sheetView.findViewById(R.id.okaybtn);
    cancelbtn = sheetView.findViewById(R.id.cancelbtn);

   okaybtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });

    cancelbtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mBottomSheetDialog.dismiss();
        }
    });
布局代码如下所示

    <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="250dp"
         android:id="@+id/bottomsheet"
         android:clipToPadding="true"
         android:background="@color/colorwhite"
 app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

        <ImageView
            android:layout_gravity="center"
            android:src="@drawable/logowhite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />

        <TextView
            android:layout_gravity="center"
            android:textSize="@dimen/textsizenormal"
            android:textColor="@color/colortheme"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/exit"
            android:padding="16dp"/>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <Button
                android:id="@+id/cancelbtn"
                android:text="Cancel"
                android:textColor="@color/colorwhite"
                android:layout_margin="10dp"
                android:textSize="@dimen/textsizenormal"
                android:background="@drawable/buttonclick"
                android:layout_weight="1"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
            <Button
                android:id="@+id/okaybtn"
                android:text="Okay"
                android:textColor="@color/colorwhite"
                android:layout_margin="10dp"
                android:textSize="@dimen/textsizenormal"
                android:background="@drawable/buttonclick"
                android:layout_weight="1"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </LinearLayout>
    </LinearLayout>

@shubhamsaini很乐意帮忙