如何主要布局设置为透明时布局内的另一个布局对话变得活跃

问题描述 投票:0回答:1

要显示在透明色的背景,当我fragmentdialog fragment取代。

我更换fragment当我选择导航菜单的一个选项,但我想显示透明背景和fragment主框架,我打开弹出式窗口提醒在白色背景。

我的导航菜单XML

       <?xml version="1.0" encoding="utf-8"?>
        <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/drawer_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true">

            <include
                layout="@layout/app_bar_main"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />


            <android.support.design.widget.NavigationView
                android:id="@+id/nav_view"
                android:layout_width="@dimen/dp400"
                android:layout_height="match_parent"
                android:background="@color/colorWhite"
                android:layout_gravity="start"
                android:fitsSystemWindows="true"
                app:headerLayout="@layout/nav_header_main">


                <ListView
                    android:id="@+id/rv_nav_data"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginTop="@dimen/dp150"></ListView>


            </android.support.design.widget.NavigationView>

        </android.support.v4.widget.DrawerLayout>


    app_bar_main xml



      <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true">

            <android.support.design.widget.AppBarLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:background="?attr/colorPrimary" >



                </android.support.v7.widget.Toolbar>


            </android.support.design.widget.AppBarLayout>

            <include layout="@layout/content_main" />

        </android.support.design.widget.CoordinatorLayout>

    content_main xml in which i am replacing my fragment

<?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"
    android:layout_marginTop="@dimen/dp60"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    >

    <!--<TextView-->
    <!--android:layout_width="wrap_content"-->
    <!--android:layout_height="wrap_content"-->
    <!--android:text="Hello World!" />-->

    <FrameLayout
        android:id="@+id/frameMain"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        ></FrameLayout>
</RelativeLayout>

    and fragment xml which I am replacing when selecting navigation option.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ll_popup_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        android:gravity="center"
        android:orientation="vertical">


        <LinearLayout
            android:id="@+id/ll_filter_report"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/dp20"
            android:layout_marginTop="@dimen/dp20"
            android:layout_marginRight="@dimen/dp20"
            android:background="@drawable/rounded_layout_white"
            android:orientation="vertical"
            android:visibility="visible">

            <LinearLayout
                android:id="@+id/ll_sub_group"
                android:layout_width="match_parent"
                android:layout_height="@dimen/dp80"
                android:orientation="horizontal"
                android:padding="@dimen/dp20"
                android:weightSum="1">

                <TextView
                    android:id="@+id/lbl_sub_group"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.5"
                    android:gravity="left|center"
                    android:text="@string/str_sub_group"
                    android:textSize="@dimen/dp20" />

                <Spinner

                    android:id="@+id/spn_sub_group"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.5"
                    android:spinnerMode="dropdown"></Spinner>

            </LinearLayout>

            <LinearLayout
                android:id="@+id/ll_client"
                android:layout_width="match_parent"
                android:layout_height="@dimen/dp80"
                android:layout_marginTop="@dimen/dp10"
                android:orientation="horizontal"
                android:padding="@dimen/dp20"
                android:weightSum="1">

                <TextView
                    android:id="@+id/lbl_client"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.5"
                    android:gravity="left|center"
                    android:text="@string/str_client"
                    android:textSize="@dimen/dp20" />

                <Spinner
                    android:id="@+id/spn_client"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.5"></Spinner>

            </LinearLayout>

            <LinearLayout
                android:id="@+id/ll_date"
                android:layout_width="match_parent"
                android:layout_height="@dimen/dp80"
                android:layout_marginTop="@dimen/dp10"
                android:orientation="horizontal"
                android:padding="@dimen/dp20"
                android:weightSum="1">

                <TextView
                    android:id="@+id/lbl_date"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.5"
                    android:gravity="left|center"
                    android:text="@string/str_as_on"
                    android:textSize="@dimen/dp20" />

                <EditText
                    android:id="@+id/edt_date"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.5"
                    android:hint="Select date"
                    android:padding="@dimen/dp10"
                    android:textColor="@color/colorLightBlue">

                </EditText>

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/dp20"
                android:gravity="center"
                android:orientation="horizontal"
                android:padding="@dimen/dp10"
                android:weightSum="1">

                <Button
                    android:id="@+id/btn_Search"
                    android:layout_width="@dimen/dp0"
                    android:layout_height="match_parent"
                    android:layout_weight="0.4"
                    android:background="@drawable/rounded_layout_blue"
                    android:text="@string/str_search"
                    android:textAllCaps="false"
                    android:textColor="@color/colorWhite" />

                <Button
                    android:id="@+id/btn_reset"
                    android:layout_width="@dimen/dp0"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="@dimen/dp20"
                    android:layout_weight="0.4"
                    android:background="@drawable/rounded_layout_blue"
                    android:text="@string/str_reset"
                    android:textAllCaps="false"
                    android:textColor="@color/colorWhite" />
            </LinearLayout>
        </LinearLayout>

    </LinearLayout>

this is my fragment java class


import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

    public class PortfolioReportFragment extends Fragment {

        private View view;
        private EditText edtDate;
        final Calendar myCalendar = Calendar.getInstance();
        private static int loginid, userrole, clientid;
        public ArrayList<String> groupTextList;
        public static ArrayList<Integer> groupIdList;
        public static ArrayList<Integer> clientIdList;
        private static ArrayList<String> clientList;
        private static Spinner spGroup, spClient;
        private Button btnSearch, btnReset;
        public static String Flag, clientids;
        private LinearLayout llPopupMain;


        @Nullable
        @Override
        public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

            view = inflater.inflate(R.layout.fragment_portfolio_report, container, false);

            initView(view);
            onClick();

            groupTextList = new ArrayList<>();
            groupIdList = new ArrayList<>();
            clientList = new ArrayList<>();
            clientIdList = new ArrayList<>();

            getActivity().getWindow().setSoftInputMode(
                    WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
            SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());

            loginid = sp.getInt("loginId", 0);
            userrole = sp.getInt("userrole", 0);
            clientid = sp.getInt("clientid", 0);


            Log.e("Lognid is:", String.valueOf(loginid));
            Log.e("clientid is:", String.valueOf(clientid));


            edtDate.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    setDate();
                }
            });

            Log.e("Size of groupidList", String.valueOf(groupIdList.size()));
            Log.e("Size of groupTextList", String.valueOf(groupTextList.size()));
            Log.e("Size of clientList", String.valueOf(clientList.size()));


            getClientGroup(String.valueOf(clientid));

            spGroup.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

                    int selectedId = groupIdList.get(1);
                    Log.e("Selected id is=", String.valueOf(selectedId));
                    Log.e("at 0", String.valueOf(groupIdList.get(0)));
                    Log.e("at 1", String.valueOf(groupIdList.get(1)));

                    getClient(selectedId);
                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {
                    getClient(0);
                }
            });


            return view;
        }

        private void initView(View v) {

            edtDate = (EditText) v.findViewById(R.id.edt_date);
            spGroup = (Spinner) v.findViewById(R.id.spn_sub_group);
            spClient = (Spinner) v.findViewById(R.id.spn_client);
            btnReset = (Button) v.findViewById(R.id.btn_reset);
            btnSearch = (Button) v.findViewById(R.id.btn_Search);
            llPopupMain = (LinearLayout)v.findViewById(R.id.ll_popup_main);
        }


        private void setDate() {
            final Calendar c = Calendar.getInstance();
            int mYear = c.get(Calendar.YEAR);
            int mMonth = c.get(Calendar.MONTH);
            int mDay = c.get(Calendar.DAY_OF_MONTH);


            //opening calander from here
            Calendar calendar = Calendar.getInstance();
            DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), R.style.DialogTheme, new DatePickerDialog.OnDateSetListener() {
                public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                    Calendar newDate = Calendar.getInstance();
                    newDate.set(year, monthOfYear, dayOfMonth-1);
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy");
                    String date = simpleDateFormat.format(newDate.getTime());
                    edtDate.setText(date);

                }

            }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));

            datePickerDialog.getDatePicker().setMaxDate(System.currentTimeMillis());
            datePickerDialog.show();
        }

        //calling group api
        private void getClientGroup(String clientid) {

            final APIInterface apiInterface = APIClient.getClient().create(APIInterface.class);

            Log.e("In getClientGroup", "");
            Log.e("client idgetClientGroup", String.valueOf(clientid));
            Log.e("loginid getClientGroup", String.valueOf(loginid));

            final FilterModel filterModel = new FilterModel("G", clientid, String.valueOf(loginid), "A", String.valueOf(userrole));
            Call<FilterModel> call1 = apiInterface.createClientGroup(filterModel);
            call1.enqueue(new Callback<FilterModel>() {
                @Override
                public void onResponse(Call<FilterModel> call, Response<FilterModel> response) {

                    FilterModel filterResponse = response.body();

                    groupTextList.clear();
                    groupIdList.clear();

                    groupTextList.add(0, "Select All");
                    groupIdList.add(0, 0);

                    Log.e("Getclientgroup:", "success");

                    for (int i = 0; i < filterResponse.getT0().size(); i++) {


                        int groupId = filterResponse.getT0().get(i).getID();
                        String groupText = filterResponse.getT0().get(i).getTEXT();

                        Log.e("Groupid==", String.valueOf(groupId));
                        Log.e("GroupText==", String.valueOf(groupText));

                        groupIdList.add(groupId);
                        groupTextList.add(groupText);


                        CustomSpinnerAdapter adapter = new CustomSpinnerAdapter(getActivity(), groupTextList);
                        spGroup.setAdapter(adapter);
                        adapter.notifyDataSetChanged();
                        // getClient(clientid);

                    }

                }

                @Override
                public void onFailure(Call<FilterModel> call, Throwable t) {

                    Log.e("Error is==", t.getMessage());
                }


            });

        }

        //calling client api
        private void getClient(final int selectedId) {

            final APIInterface apiInterface = APIClient.getClient().create(APIInterface.class);

            Log.e("In getclient", "");
            Log.e("client idgetClientGroup", String.valueOf(selectedId));
            Log.e("loginid getClientGroup", String.valueOf(loginid));

            final FilterModel filterModel = new FilterModel("C", String.valueOf(selectedId), String.valueOf(loginid), "A", "99");
            Call<FilterModel> call1 = apiInterface.createClientGroup(filterModel);
            call1.enqueue(new Callback<FilterModel>() {
                @Override
                public void onResponse(Call<FilterModel> call, Response<FilterModel> response) {

                    FilterModel filterResponse = response.body();
                    clientList.clear();
                    Log.e("Getclient:", "success");
                    clientList.add(0, "Select All");


                    for (int i = 0; i < filterResponse.getT0().size(); i++) {


                        int groupId = filterResponse.getT0().get(i).getID();
                        String groupText = filterResponse.getT0().get(i).getTEXT();

                        Log.e("Groupid in client==", String.valueOf(groupId));
                        Log.e("GroupText in client==", String.valueOf(groupText));

                        //set client from response in clientlist
                        clientList.add(groupText);
                        clientIdList.add(groupId);
    //                    Log.e("Selected id=", String.valueOf(selectedId));
    //                    Log.e("client id list=", clientIdList.toString());

                        if (selectedId == (0)) {
                            ArrayList<String> mList = new ArrayList<String>();
                            mList.add("");
                            CustomSpinnerAdapter adapter = new CustomSpinnerAdapter(getActivity(), mList);
                            spClient.setAdapter(adapter);
                            adapter.notifyDataSetChanged();

                        } else {

                            CustomSpinnerAdapter adapter = new CustomSpinnerAdapter(getActivity(), clientList);
                            spClient.setAdapter(adapter);
                            adapter.notifyDataSetChanged();


                        }


                    }

                }


                @Override
                public void onFailure(Call<FilterModel> call, Throwable t) {

                    Log.e("Error is==", t.getMessage());
                }


            });

        }

        private void onClick() {

            btnSearch.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    if (spClient.getSelectedItemPosition() != 0) {

                        Flag = "CL";
                        clientids = String.valueOf(clientIdList.get(spClient.getSelectedItemPosition()));
                        Log.e("clientids CL", clientids);


                    } else if (spGroup.getSelectedItemPosition() != 0) {

                        Flag = "SG";
                        clientids = String.valueOf((groupIdList.get(spGroup.getSelectedItemPosition())));
                        Log.e("clientids SG", clientids);


                    } else {

                        Flag = "G";
                        clientids = String.valueOf(clientid);
                        Log.e("clientids G", clientids);

                    }

                    Intent i = new Intent(getActivity(), SearchActivity.class);
                    i.putExtra("Flag", Flag);
                    i.putExtra("date",edtDate.getText().toString());
                    i.putExtra("clientIds", clientids);
                    startActivity(i);

                }
            });

            btnReset.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    spGroup.setSelection(0);
                    edtDate.setText("Select Date");


                }
            });
        }


    }
android android-layout android-dialogfragment
1个回答
0
投票

应用透明背景布局

© www.soinside.com 2019 - 2024. All rights reserved.