将活动显示为对话框

时间:2019-09-12 04:06:02

标签: android android-activity dialog

这是我想成为对话的活动:

public class TrainerBookingDialogActivity extends AppCompatActivity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_trainer_booking_dialog);

    }



  <activity android:name="com.clearmindai.trainer.module.bookdialog.TrainerBookingDialogActivity"
            android:theme="@android:style/Theme.Holo.Light.Dialog"></activity>

我这样称呼它:

  public static  void showBookedDialog(Context context) {
        Intent intent=new Intent(getApplicationContext(), TrainerBookingDialogActivity.class);
        context.startActivity(intent);
        //show dialog
    }

但是错误显示给我:

  

您需要与此同时使用Theme.AppCompat主题(或后代)   活动。

1 个答案:

答案 0 :(得分:0)

尝试此代码

public class MyCustomDialogFragment extends DialogFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
 }
 @Override
 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle s 
 avedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_my_custom_dialog, container, false); 
   // Do all the stuff to initialize your custom view

    return v;
} 
}

请检查此链接click here