사용자 지정 DialogFragment를 조각 위에 투명하게 만들 수 없습니다. item = (LinearLayout)layout.findViewById(R.id.display_item); populateItemData(item,

(전체 화면을 차지하는) 조각에 대한 대화 상자를 만들어야합니다. 이 대화 상자는 조각 외부가 어둡게 표시된 조각 위에 배치되는 부동 대화 상자 여야합니다.

사용자 지정 대화 상자의 경우 곡선 가장자리가있는 linearLayout이 있습니다. 내가 무엇을하든 대화 상자에는 모든면에 검정색 테두리가 있습니다 (매우 작음). 나는 그것을 투명하게 만들고 사라지기 위해 모든 것을 시도했습니다 (모든 대화 상자는 선형 레이아웃-곡선 상자입니다)

DialogFragment의 경우 이것은 onCreateView에 대한 것입니다.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
    LinearLayout layout =(LinearLayout)inflater.inflate(R.layout.custom_dialog, null);
    LinearLayout item = (LinearLayout)layout.findViewById(R.id.display_item);
    populateItemData(item, inflater);
    return layout;
}

custom_dialog는 android : backgroung이 # 000000으로 설정된 LinearLayout입니다.

이것은 사용자 정의 대화 상자의 스타일입니다.

<style name="CustomDialog" parent="android:style/Theme.Dialog">
    <item name="android:windowBackground">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:alwaysDrawnWithCache">false</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

이 스타일로 모든 종류의 조합을 시도했는데 (온라인에서 본 것에서) 성가신 검은 테두리를 없앨 수 없습니다. LinearLayout 배경을 다른 것으로 설정하면 흰색 또는 다른 색상으로 칠할 수 있습니다. # 000000 …

나는 이것에 말 그대로 3-4 시간을 보냈습니다. 다른 누군가가 도울 수 있기를 바랍니다.



답변

시험

getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

당신 DialogFragmentonCreateView


답변

이 작업을 시도하십시오 ( 어떻게 100 % 사용자 정의 DialogFragment ) 대화 상자에 대한 작업

    Dialog dialog = new Dialog(getActivity());

    dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);

    dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        // layout to display
    dialog.setContentView(R.layout.add_edit);

    // set color transpartent
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

    dialog.show();

답변

나를 위해 일한 것처럼 테마 설정

<style name="MyDialog" parent="Base.Theme.AppCompat.Light.Dialog">
    <item name="android:windowBackground">@android:color/transparent</item>
</style>

그리고 다음과 같은 대화 조각 세트에서

public class Progress extends DialogFragment {


int style = DialogFragment.STYLE_NO_TITLE;
int theme = R.style.MyDialog;

public Progress() {
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setStyle(style, theme);
}

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

답변

onActivityCreated

getDialog().getWindow().getAttributes().alpha = 0.9f; // An alpha value to apply to this entire window. An alpha of 1.0 means fully opaque and 0.0 means fully transparent

에 대한 DialogFragment투명


답변

완전히 투명하게 사용하려면 :
setStyle (DialogFragment.STYLE_NO_FRAME, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);

사용자 정의 배경의 경우 값 폴더 (values ​​/ style.xml)에 스타일 파일을 만들고 사용합니다.
setStyle (DialogFragment.STYLE_NO_FRAME, yourpackagename.R.style.YOURE_CUSTOM_STYLE);

스타일 파일에서 atribute :
android : windowBackground@ color / DialogBackgroundBlackSemiTransparent로 재정의합니다.


답변

이것을 Dialog Fragment 또는 BottomSheetDialogFragment 에 추가하여 달성 할 수 있습니다.

에서 onCreateDialog방법

@Override
   public Dialog onCreateDialog(Bundle savedInstanceState) {
       Dialog dialog = super.onCreateDialog(savedInstanceState);
       dialog.getWindow().setGravity(Gravity.BOTTOM);
       dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
       dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
       return dialog;
   }

답변

<style name="BaseDialogTheme" parent="Base.Theme.AppCompat.Light.Dialog">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="colorControlNormal">@color/colorAccent</item>
    <item name="colorControlActivated">@color/colorAccent</item>

    <item name="android:windowFullscreen">true</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:colorBackgroundCacheHint">@null</item>
    <item name="android:colorBackground">@android:color/transparent</item>
    <item name="android:windowIsTranslucent">true</item>


    <item name="android:windowIsFloating">true</item>
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
    <item name="android:windowActionModeOverlay">false</item>
    <item name="android:windowCloseOnTouchOutside">true</item>
    <item name="android:backgroundDimAmount">.00</item>//this line is changed alpha from 1.0 to 0.0(full transparent)

</style>



@Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(STYLE_NO_FRAME, R.style.BaseDialogTheme);
    }