Я создал пользовательский макет диалога и пытаюсь отобразить диалог в виде действия вместо того, чтобы надувать вид внутри диалогового окна предупреждения. Но диалог отображается не так, как хотелось бы. Пожалуйста, посмотрите.
Настраиваемый макет диалога
Активность в диалоговом окне показывается как показано ниже
Вы можете взглянуть на код ниже
MainActivity
public class MainActivity extends AppCompatActivity {
private static final int PROFILE_PHOTO = 1;
private ImageView mImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mImageView = findViewById(R.id.image);
mImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showImageOptionsDialog();
}
});
}
private void showImageOptionsDialog() {
Intent imageDialogIntent = new Intent(this, ImageDialogActivity.class);
startActivityForResult(imageDialogIntent, PROFILE_PHOTO);
}
}
ImageDialogActivity
public class ImageDialogActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_dialog);
}
}
activity_image_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="match_parent"
android:padding="@dimen/sixteen"
android:clipToPadding="false"
tools:context=".ImageDialogActivity">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="@dimen/eight"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/label_profile_pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="@string/label_profile_photo"
android:textColor="@color/primary_text"
android:textSize="@dimen/dialog_label"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="@dimen/divider_height"
android:layout_marginTop="40dp"
android:background="@color/secondary_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/option_gallery" />
<Button
android:id="@+id/btn_cancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/cancel_button_bg"
android:text="@string/action_cancel"
android:textAllCaps="false"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/divider" />
<TextView
android:id="@+id/option_gallery"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:drawableTop="@mipmap/ic_pick_img"
android:drawablePadding="@dimen/eight"
android:gravity="center"
android:text="@string/option_gallery"
android:textColor="@color/primary_text"
app:layout_constraintEnd_toStartOf="@+id/option_remove_pic"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/label_profile_pic" />
<TextView
android:id="@+id/option_remove_pic"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:drawableTop="@mipmap/ic_remove_pic"
android:drawablePadding="@dimen/eight"
android:gravity="center"
android:text="@string/option_remove_photo"
android:textColor="@color/primary_text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/option_gallery"
app:layout_constraintTop_toTopOf="@+id/option_gallery"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
Manifest
<activity
android:name=".ImageDialogActivity"
android:theme="@style/Theme.AppCompat.Light.Dialog" />
Я не могу понять проблему. Пожалуйста помоги. Привет!