mirror of
https://github.com/etesync/android
synced 2024-12-23 15:18:14 +00:00
Webview: fix behaviour of toolbar back button and simplify.
This commit is contained in:
parent
3a83cf8303
commit
987076d95e
@ -194,11 +194,7 @@
|
||||
android:label="@string/debug_info_title">
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ui.WebViewActivity"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:parentActivityName=".ui.AccountsActivity"/>
|
||||
<activity android:name=".ui.WebViewActivity" />
|
||||
|
||||
<provider
|
||||
android:name="android.support.v4.content.FileProvider"
|
||||
|
@ -7,9 +7,11 @@ import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebResourceError;
|
||||
@ -28,7 +30,7 @@ public class WebViewActivity extends AppCompatActivity {
|
||||
|
||||
private WebView mWebView;
|
||||
private ProgressBar mProgressBar;
|
||||
private Toolbar mToolbar;
|
||||
private ActionBar mToolbar;
|
||||
|
||||
public static void openUrl(Context context, Uri uri) {
|
||||
Intent intent = new Intent(context, WebViewActivity.class);
|
||||
@ -41,9 +43,9 @@ public class WebViewActivity extends AppCompatActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_webview);
|
||||
mToolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(mToolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
mToolbar = getSupportActionBar();
|
||||
mToolbar.setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
Uri uri = getIntent().getParcelableExtra(KEY_URL);
|
||||
uri = addQueryParams(uri);
|
||||
@ -86,7 +88,6 @@ public class WebViewActivity extends AppCompatActivity {
|
||||
mWebView.setWebChromeClient(new WebChromeClient() {
|
||||
|
||||
public void onProgressChanged(WebView view, int progress) {
|
||||
mToolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
if (progress == 100) {
|
||||
mToolbar.setTitle(view.getTitle());
|
||||
mProgressBar.setVisibility(View.INVISIBLE);
|
||||
@ -194,4 +195,15 @@ public class WebViewActivity extends AppCompatActivity {
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
if (!getSupportFragmentManager().popBackStackImmediate()) {
|
||||
finish();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,34 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:theme="@style/ThemeOverlay.AppCompat.ActionBar">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"/>
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="-8dp"
|
||||
android:layout_marginTop="-8dp"
|
||||
android:max="100"
|
||||
android:maxHeight="1dp"/>
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
<WebView
|
||||
android:id="@+id/webView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="-8dp"
|
||||
android:layout_marginTop="-8dp"
|
||||
android:max="100"
|
||||
android:maxHeight="1dp" />
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
Loading…
Reference in New Issue
Block a user