gpt4 book ai didi

java - 无法解析方法 'getLayoutInflater()' - Android Java

转载 作者:行者123 更新时间:2023-12-01 11:20:56 25 4
gpt4 key购买 nike

我想在我的 webView 中添加全屏模式 - 用于 YouTube 视频 -。我发现了这个例子 https://stackoverflow.com/a/16179544/5070495 。我已遵循所有步骤,调整代码,但我有一个问题。

我使用 rootView 作为我的布局,但我不知道如何在 getLayoutInflater() 之前使用它。

问题是:

View loadingView = getLayoutInflater().inflate(R.layout.view_loading_video, null); // Your own view, read class comments

所有代码:

public class vod extends Fragment {
private WebView wv7;
public static final String TAG = "VOD";
private VideoEnabledWebView webView;
private VideoEnabledWebChromeClient webChromeClient;


@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {


View rootView = inflater.inflate(R.layout.vod, container, false);
// Set layout
//rootView.findViewById(R.layout.vld);

// Save the web view
wv7 = (VideoEnabledWebView) rootView.findViewById(R.id.webView7);

// Initialize the VideoEnabledWebChromeClient and set event handlers
View nonVideoLayout = rootView.findViewById(R.id.nonVideoLayout); // Your own view, read class comments
ViewGroup videoLayout = (ViewGroup) rootView.findViewById(R.id.videoLayout); // Your own view, read class comments
View loadingView = getLayoutInflater().inflate(R.layout.view_loading_video, null); // Your own view, read class comments
webChromeClient = new VideoEnabledWebChromeClient(nonVideoLayout, videoLayout, loadingView, webView) // See all available constructors...
{
// Subscribe to standard events, such as onProgressChanged()...
@Override
public void onProgressChanged(WebView view, int progress) {
// Your code...
}
};
webChromeClient.setOnToggledFullscreen(new VideoEnabledWebChromeClient.ToggledFullscreenCallback() {
@Override
public void toggledFullscreen(boolean fullscreen) {
// Your code to handle the full-screen change, for example showing and hiding the title bar. Example:
if (fullscreen) {
WindowManager.LayoutParams attrs = getActivity().getWindow().getAttributes();
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
attrs.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
getActivity().getWindow().setAttributes(attrs);
if (android.os.Build.VERSION.SDK_INT >= 14) {
getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
}
} else {
WindowManager.LayoutParams attrs = getActivity().getWindow().getAttributes();
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
attrs.flags &= ~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
getActivity().getWindow().setAttributes(attrs);
if (android.os.Build.VERSION.SDK_INT >= 14) {
getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
}
}

}
});
wv7.setWebChromeClient(webChromeClient);

// Navigate everywhere you want, this classes have only been tested on YouTube's mobile site
wv7.loadUrl("http://m.youtube.com");


}
public void onBackPressed()
{
// Notify the VideoEnabledWebChromeClient, and handle it ourselves if it doesn't handle it
if (!webChromeClient.onBackPressed())
{
if (wv7.canGoBack()) {
wv7.goBack();
}
}
}
}

感谢您的帮助:p

最佳答案

为什么要调用 getLayoutInflater?从参数来看你有充气机更改它:

View loadingView = inflater.inflate(R.layout.view_loading_video, null); // Your own view, read class comments

编辑:第二种解决方案:

View loadingView = getActivity().getLayoutInflater().inflate(R.layout.view_loading_video, null);

但我认为第一个解决方案更好。

关于java - 无法解析方法 'getLayoutInflater()' - Android Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31234807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com