Android Fragment和getWindow()

时间:2011-09-29 17:08:01

标签: android

public class AircraftFragmentTab extends Fragment{
  private String ac;

  public AircraftFragmentTab(String AC){
      ac = AC;

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

         ??? getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
          WebView wv = (WebView) aircraftView.findViewById(R.id.webac);
          wv.getSettings().setJavaScriptEnabled(true);
          wv.loadUrl("http://ABCD/ACInfo.aspx?AC=" + ac);

         return aircraftView;
     }

}

我使用的是webView,类扩展自Fragment。我如何在这里使用getWindow()?

2 个答案:

答案 0 :(得分:69)

您可以使用getActivity().getWindow()
getActivity()将返回此片段当前与之关联的活动。

答案 1 :(得分:0)

来自Activity

的示例
getWindow().setStatusBarColor(getResources().getColor(R.color.black));

来自Fragment

的示例
requireActivity().getWindow().setStatusBarColor(getResources().getColor(R.color.black));