Фоновое изображение устанавливается для всего фрагмента вместо внутреннего lineatlayout - PullRequest
0 голосов
/ 23 ноября 2018

Окончательный результат - фрагмент полноэкранного диалога с фоновым изображением без кнопок.

Хотя изображения установлены в качестве фона для внутреннего макета "imageLayout", я установлю другой макет внутри "imageLayout", поэтому я не могузамените его на imageview

Я создал пользовательский фрагмент диалога со следующим xml-кодом "frag_bottom.xml":

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:id="@+id/fragmentBottomLinearLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

</LinearLayout>

и стилевым кодом "styles.xml":

<resources>

    <color name="SemiWhite">#ccffffff</color>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="FullScreenDialogStyle" parent="Theme.AppCompat.Dialog">
        <item name="android:padding">0dp</item>
        <item name="android:windowNoTitle">true</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorPrimary">@color/colorPrimary</item>

        <item name="android:windowFullscreen">true</item>

        <item name="android:windowIsFloating">false</item>


        <item name="android:windowBackground">@color/SemiWhite</item>

    </style>

</resources>

Файл кода JAVA:

public class ImageDialogFragment extends DialogFragment {
        private List pass = new ArrayList<String>();

        public static String TAG = "FullScreenDialog";

        public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {

            return super.onCreateDialog(savedInstanceState);

        }

        @Nullable
        @Override
        public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
            return inflater.inflate(R.layout.fragment_bottom, container, false);
        }

        @Override
        public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
            super.onViewCreated(view, savedInstanceState);


            // Get Fragment belonged Activity
            final FragmentActivity fragmentBelongActivity = getActivity();


            String image_path = null;
            if (getArguments() != null) {

                int sNextCharText = Integer.parseInt(getArguments().getString("sNextCharText"));
                image_path = getArguments().getString("sImagePath");

            }

            final LinearLayout layout = view.findViewById(R.id.fragmentBottomLinearLayout);

            LinearLayout imageLayout = new LinearLayout(getActivity());
            imageLayout.setOrientation(LinearLayout.VERTICAL);
            imageLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            if (!image_path.isEmpty()) {
                // Convert image to
                Bitmap bitmapImage = BitmapFactory.decodeFile(image_path);
                Drawable d = new BitmapDrawable(getResources(), bitmapImage);
                imageLayout.setBackground(d);
            }

            PasswordOnlyImageConstruction(imageLayout, fragmentBelongActivity);
            layout.addView(imageLayout);

            LinearLayout buttonLayout = new LinearLayout(getActivity());
            buttonLayout.setOrientation(LinearLayout.HORIZONTAL);
            buttonLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            buttonLayouteConstruction(buttonLayout, getActivity());
            layout.addView(buttonLayout);


        }


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(DialogFragment.STYLE_NORMAL, R.style.FullScreenDialogStyle);
    }
private void buttonLayouteConstruction(LinearLayout imageLayout, FragmentActivity activity) {
    Button doneButton = new Button(activity);
    doneButton.setText("Done");
    doneButton.setEnabled(!pass.isEmpty());
    doneButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {

        }
    });

    Button cancelButton = new Button(activity);
    cancelButton.setText("Cancel");
    cancelButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {

            // Dismiss DialogFragment
            getDialog().dismiss();
        }
    });
}
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...