2017-05-08 79 views
0

我有一個自定義的BttomSheetDialogFragment,我想在仰視圖回合角落BottomSheetDialogFragment

頂部圓角,這是我的自定義類,充氣我的佈局,我想從底部

View mView; 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    mView = inflater.inflate(R.layout.charge_layout, container, false); 
    initChargeLayoutViews(); 
    return mView; 
} 
出現

而且我有這個XML資源文件作爲背景:

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle" 
> 
<corners android:topRightRadius="35dp" 
    android:topLeftRadius="35dp" 
    /> 
<solid android:color="@color/white"/> 

<padding android:top="10dp" 
    android:bottom="10dp" 
    android:right="16dp" 
    android:left="16dp"/> 

但問題是,當我設置這個資源文件作爲我的佈局的根元素的背景,邊角依然不圓

,我不能下面的代碼使用方法:

this.getDialog().getWindow().setBackgroundDrawableResource(R.drawable.charge_layout_background); 

的Cuz其覆蓋BottomSheetDialog的默認背景,並且不會有我上面的底部查看任何半透明的灰色

+0

你有沒有解決這個問題? –

+0

@JohnErnestGuadalupe不幸的是我無法解決這個問題 –

回答

1

我今天檢查同樣的事情,是的,你說得對,下面的代碼

this.getDialog().getWindow().setBackgroundDrawableResource(R.drawable.charge_layout_background); 

適用於片段的背景,所以不是你應該從對話窗口中bottomsheet這裏瀏覽和修改的背景是代碼

@SuppressLint("RestrictedApi") 
    @Override 
    public void setupDialog(Dialog dialog, int style) { 
     super.setupDialog(dialog, style); 
     View rootView = getActivity().getLayoutInflater().inflate(R.layout.view_member_info,null,false); 
     unbinder = ButterKnife.bind(this, rootView); 
     adjustUIComponents(); 
     dialog.setContentView(rootView); 
     FrameLayout bottomSheet = (FrameLayout) dialog.getWindow().findViewById(android.support.design.R.id.design_bottom_sheet); 
     bottomSheet.setBackgroundResource(R.drawable.container_background); 
    } 

這裏bottomsheet是要改變實際的看法。

0

解決此問題的另一種方法是擴展BottomSheetDialog並創建一個適合您需求的自定義類。您可以對佈局xml文件執行相同的操作,並添加背景或任何其他需要的自定義。這也有一個好處,你不會依賴於Android(android.support.design.R.id.design_bottom_sheet)使用的id名稱,同時改變背景(儘管id名稱的改變很少發生AFAIK)。

0

通過Koma Yipanother question回答爲我工作,你應該嘗試一下。

創建繪製一個xml,說dialog_bg.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="@color/white"/> 
    <corners android:radius="30dp" /> 
    <padding 
     android:left="10dp" 
     android:top="10dp" 
     android:right="10dp" 
     android:bottom="10dp" /> 
</shape> 

把這個在你的佈局XML根節點:

將其設置爲背景,你的佈局XML

android:background="@drawable/dialog_bg" 

onCreateView()把這個:

設置你的對話框的背景透明

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