[英]why does gradientdrawable.setBackground makes my app crash?
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
GradientDrawable drawable = new GradientDrawable();
drawable.setShape(GradientDrawable.RECTANGLE);
drawable.setStroke(3, Color.GREEN);
View view = inflater.inflate(R.layout.primary, container, false);
LinearLayout layout = (LinearLayout ) view.findViewById(R.layout.primary);
// 1 layout.setBackground(fragmentBorder); <----
// ^ above line causes the crash ^
layout.setBackgroundDrawable(drawable);
return view;
}
沒有編譯錯誤,當我測試驅動器時它只會崩潰
LinearLayout layout = (LinearLayout ) view.findViewById(R.layout.primary);
請更改以上行為
LinearLayout layout = (LinearLayout ) view.findViewById(R.id.primary);
您的線性布局保持為空,這就是它崩潰的原因
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.