import android.view.MenuItem;
import android.view.View;
import android.view.ViewTreeObserver;
+import android.view.Window;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
- urlTextBox = (EditText) findViewById(R.id.urlTextBox);
swipeToRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayoutContainer);
mainWebView = (WebView) findViewById(R.id.mainWebView);
- progressBar = (ProgressBar) findViewById(R.id.progressBar);
- favoriteIcon = (ImageView) findViewById(R.id.favoriteIcon);
- // Remove the title from the action bar.
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
+ // Remove the title from the action bar.
actionBar.setDisplayShowTitleEnabled(false);
- // actionBar.setHideOnContentScrollEnabled(true);
+
+ // Add the custom app_bar layout, which shows the favoriteIcon, urlTextBar, and progressBar.
+ actionBar.setCustomView(R.layout.app_bar);
+ actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
+
+ // Initialize the variables for favoriteIcon, urlTextBox, and progressBar
+ favoriteIcon = (ImageView) actionBar.getCustomView().findViewById(R.id.favoriteIcon);
+ urlTextBox = (EditText) actionBar.getCustomView().findViewById(R.id.urlTextBox);
+ progressBar = (ProgressBar) actionBar.getCustomView().findViewById(R.id.progressBar);
+
+ //actionBar.setHideOnContentScrollEnabled(true);
}
// Implement swipe down to refresh.
+<!-- SwipeRefreshLayout allows the user to swipe down to refresh. -->
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayoutContainer"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
- <!-- SwipeRefreshLayout allows the user to swipe down to refresh. -->
- <RelativeLayout
- android:id="@+id/relativeLayoutContainer"
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
+ <WebView
+ android:id="@+id/mainWebView"
android:layout_width="match_parent"
android:layout_height="match_parent"
- tools:context=".Webview" >
-
- <!-- FrameLayout lets the ProgressBar float on top of urlTextBox. -->
- <FrameLayout
- android:id="@+id/addressBarFrameLayout"
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
-
- <LinearLayout
- android:id="@+id/addressBarLinearLayout"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
-
- <ImageView
- android:id="@+id/favoriteIcon"
- android:src="@drawable/ic_language_black_24dp"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center" />
-
- <!-- android:inputType="textUri" sets the keyboard to have a go arrow. -->
- <!-- android:layout_weight="1" makes urlTextBox take up all the remaining space. -->
- <EditText
- android:id="@+id/urlTextBox"
- android:layout_width="0dp"
- android:layout_weight="1"
- android:layout_height="wrap_content"
- android:inputType="textUri"
- android:imeOptions="actionGo" />
- </LinearLayout>
-
- <!-- android:max changes the maximum ProgressBar value from 10000 to 100 to match progress percentage. -->
- <ProgressBar
- android:id="@+id/progressBar"
- style="?android:attr/progressBarStyleHorizontal"
- android:layout_width="fill_parent"
- android:layout_height="7dp"
- android:layout_gravity="bottom"
- android:max="100"
- android:progressTint="#FF0097FF"
- android:progressBackgroundTint="#FFFFFFFF"
- android:visibility="gone" />
- </FrameLayout>
-
- <WebView
- android:id="@+id/mainWebView"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_below="@id/addressBarFrameLayout"
- android:focusable="true"
- android:focusableInTouchMode="true" />
-
- </RelativeLayout>
+ android:focusable="true"
+ android:focusableInTouchMode="true" />
</android.support.v4.widget.SwipeRefreshLayout>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- FrameLayout lets the ProgressBar float on top of urlTextBox. -->
+<FrameLayout
+ android:id="@+id/addressBarFrameLayout"
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <LinearLayout
+ android:id="@+id/addressBarLinearLayout"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+
+ <ImageView
+ android:id="@+id/favoriteIcon"
+ android:src="@drawable/ic_language_black_24dp"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:contentDescription="@string/favorite_icon"/>
+
+ <!-- android:inputType="textUri" sets the keyboard to have a go arrow. -->
+ <!-- android:layout_weight="1" makes urlTextBox take up all the remaining space. -->
+ <EditText
+ android:id="@+id/urlTextBox"
+ android:layout_width="0dp"
+ android:layout_weight="1"
+ android:layout_height="wrap_content"
+ android:inputType="textUri"
+ android:imeOptions="actionGo" />
+ </LinearLayout>
+
+ <!-- android:max changes the maximum ProgressBar value from 10000 to 100 to match progress percentage. -->
+ <ProgressBar
+ android:id="@+id/progressBar"
+ style="?android:attr/progressBarStyleHorizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="7dp"
+ android:layout_gravity="bottom"
+ android:max="100"
+ android:progressTint="#FF0097FF"
+ android:progressBackgroundTint="#FFFFFFFF"
+ android:visibility="gone" />
+</FrameLayout>
\ No newline at end of file
android:title="@string/home"
android:orderInCategory="100"
android:icon="@drawable/ic_home_black_24dp"
- app:showAsAction="ifRoom" />
+ app:showAsAction="never" />
<item
android:id="@+id/back"
android:title="@string/back"
android:orderInCategory="200"
android:icon="@drawable/ic_back"
- app:showAsAction="ifRoom" />
+ app:showAsAction="never" />
<item
android:id="@+id/forward"
android:title="@string/forward"
android:orderInCategory="300"
android:icon="@drawable/ic_forward"
- app:showAsAction="ifRoom" />
+ app:showAsAction="never" />
</menu>
<resources>
- // Activities.
+ <!-- Activities. -->
<string name="privacy_browser">Privacy Browser</string>
- // Menu.
+ <!-- Custom App Bar. -->
+ <string name="favorite_icon">Favorite Icon</string>
+
+ <!-- Menu. -->
<string name="home">Home</string>
<string name="back">Back</string>
<string name="forward">Forward</string>
- // Layout.
- <string name="go_button">Go</string>
-
</resources>