public class MainActivity extends AppCompatActivity {
private WebView webView;
public ValueCallback<Uri[]> uploadMessage;
public static final int REQUEST_SELECTED_FILE = 100;
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == REQUEST_SELECTED_FILE) {
if (uploadMessage == null) return;
uploadMessage.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, intent));
uploadMessage = null;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
webView.setWebChromeClient(new WebChromeClient(){
public boolean onShowFileChooser(WebView view, ValueCallback<Uri[]> filePathCallback,WebChromeClient.FileChooserParams fileChooserParams){
if(uploadMessage != null){
uploadMessage.onReceiveValue(null);
}
uploadMessage = filePathCallback;
Intent intent;
intent = fileChooserParams.createIntent();
try{
startActivityForResult(intent,REQUEST_SELECTED_FILE);
} catch (ActivityNotFoundException e){
uploadMessage = null;
return false;
}
return true;
}
});
}
}
https://xn--90acbu5aj5f.xn--p1ai/?p=5129
AndroidManifest.xml
<application
android:theme="@style/Theme.Test.Launcher"
</application>
themes.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="Theme.Test.Launcher">
<item name="android:windowBackground">@drawable/launch_screen</item>
</style>
</resources>
launch_screen.xml для векторного изображения
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
<item android:drawable="@color/orange"/>
<item android:drawable="@drawable/logo_splash" android:gravity="center"/>
</layer-list>
launch_screen.xml для png
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
<item android:drawable="@color/red"/>
<item>
<bitmap
android:src="@drawable/logo_splash"
android:gravity="center"/>
</item>
</layer-list>
MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.Theme_Test);
super.onCreate(savedInstanceState);
}
}
activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"/>
<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_centerInParent="true"
android:indeterminateTint="@color/orange"/>
</RelativeLayout>
Для своей картинки вместо стандартного ProgressBar:
<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_centerInParent="true"
android:indeterminateDrawable="@drawable/progress"/>
progress.xml
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/progress_icon"
android:pivotX="50%"
android:pivotY="50%"/>
MainActivity.java
public class MainActivity extends AppCompatActivity {
private WebView webView;
private ProgressBar spinner;
String ShowOrHideWebViewInitialUse = "show";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
webView = findViewById(R.id.webView);
spinner = findViewById(R.id.progress);
webView.setWebViewClient(new CustomWebViewClient());
}
private class CustomWebViewClient extends WebViewClient{
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon){
spinner.setVisibility(View.VISIBLE);
if(ShowOrHideWebViewInitialUse.equals("show")){
view.setVisibility(View.INVISIBLE);
}
}
@Override
public void onPageFinished(WebView view, String url){
ShowOrHideWebViewInitialUse = "hide";
spinner.setVisibility(View.GONE);
view.setVisibility(View.VISIBLE);
super.onPageFinished(view, url);
}
}
}