【问题标题】:How to use WebView inside a Fragment l? [closed]如何在 Fragment l 中使用 WebView? [关闭]
【发布时间】:2016-03-19 08:00:45
【问题描述】:

大家好,我有一个问题。 如何在Fragment 中使用WebView? 我知道如何在Activity 中使用WebView,但我不知道如何在Fragment 中执行此操作。 因为你不能在Fragment 中使用FindViewById

感谢您的帮助

弗洛帝国

【问题讨论】:

  • 欢迎来到 Stack Overflow。请看How to Ask
  • 请回答我的问题

标签: android fragment


【解决方案1】:

你必须让你的onCreateView 像这样

@Override
public View onCreateView(LayoutInflater layoutInflater, ViewGroup container, Bundle savedInstanceState) {
    View v = layoutInflater.inflate(R.layout.my_fragment, container, false);
    WebView webview = (WebView) v.findViewById(R.id.webview_id);
    // other stuff
    return v;
} 

【讨论】:

  • 谢谢你帮助我 :-) 祝你有美好的一天
【解决方案2】:

可以Fragment中使用findViewById() 方法。比如在onCreateView方法中:

@Override
public View onCreateView(LayoutInflater layoutInflater, ViewGroup container, Bundle savedInstanceState) {
    View fragmentView = layoutInflater.inflate(R.layout.your_fragment, container, false);

    // and you can use findViewById() method on fragmentView

    View v = fragmentView.findViewById(R.id.your_view);
    ... 
    return fragmentView;
} 

希望,它会有所帮助。

【讨论】:

  • 非常感谢您。祝你有美好的一天
猜你喜欢
  • 2015-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多