DialogFragment视图 - ARGB背景

时间:2016-05-24 11:07:21

标签: android android-dialogfragment argb

如何在对话框片段中添加带有argb背景的视图?

public class MyDialogFragment extends DialogFragment {

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
        ViewGroup rootView = (ViewGroup)inflater.inflate(R.layout.dialog, container);
        TextView child = new TextView(getActivity());
        child.setBackgroundColor(Color.parseColor("#4d000000"));   
        child.setText("this sample of stackoverflow.com");
        child.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));  
        rootView.addView(child);
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        return rootView;
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) { 
        return super.onCreateDialog(savedInstanceState);    
    }
}

dialog.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

</LinearLayout>

0 个答案:

没有答案