I am working with an app which will load a website Inside the app .Now i want to add a ProgressBar in action bar without swipe up to repress feature.
Like that
I am using Fragment in my app.
WebviewFragment
public class WebviewFragment extends Fragment {
WebView webView;
String newslink;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_webview, container, false);
newslink = getArguments().getString("LINK");
webView = (WebView) view.findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(newslink);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
webView.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
webView.goBack();
return true;
}
return false;
}
});
return view;
}
}
fragment_webview.XML
<?xml version="1.0" encoding ="utf-8"?
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webView" />
</LinearLayout>
Any solution for me ?
ProgressBars are used as loading indicators in android applications. These are generally used when the application is loading the data from the server or database. There are different types of progress bars used within the android application as loading indicators.
Indeterminate mode is the default for progress bar and shows a cyclic animation without a specific amount of progress indicated. The following example shows an indeterminate progress bar: <ProgressBar android:id="@+id/indeterminateBar" android:layout_width="wrap_content" android:layout_height="wrap_content" />
A SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch the thumb and drag left or right to set the current progress level or use the arrow keys. Placing focusable widgets to the left or right of a SeekBar is discouraged.
An on-screen toolbar displaying icons that are clicked or tapped to perform various functions. For example, the menu bar at the top of an Android app is called an action bar.
if you want add progress to actionbar call this method before setlayout
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
UPDATE where should request window feature
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_main);
.... // other code goes here
}
and call this method when you want run it
EDIT in fragment you can add getActivity()
before requestWindowFeature
to be getActivity().requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setProgressBarIndeterminateVisibility(true); // turn progress on
setProgressBarIndeterminateVisibility(false); // turn progress off
hope this work , my recommendation to use toolbar
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/material_green_500"
android:minHeight="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<ProgressBar
android:id="@+id/toolbar_progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateTint="#795548"
android:indeterminateTintMode="src_in"
android:layout_gravity="right"
/>
</android.support.v7.widget.Toolbar>
Why I recommended toolbar with ProgressBar ?
for two reasons , First setSupportProgressBarIndeterminate deprecated.
Second easy to use just set setVisibility
method to make it visible call setVisibility(View.VISIBLE);
to hide view call setVisibility(View.GONE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With