如何在片段中使用Material ProgressBar

时间:2016-09-15 06:18:28

标签: android android-fragments progress-bar

我使用了库来获取材质进度条 https://github.com/pnikosis/materialish-progress

当我在Activity扩展AppCompatActivity中使用它时,它运行正常但是当我在Fragment中使用它时,应用程序崩溃了... 我检查了LogCat,出现了类似的错误 Runtime: you need to use Theme.AppCompat theme 如何使它在片段中工作。

这里是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"
    xmlns:wheel="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:orientation="vertical" 
    android:background="#ffffff">

    <com.pnikosis.materialishprogress.ProgressWheel
        android:id="@+id/progressBar1"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_width="80dp"
        android:layout_height="80dp"
        wheel:matProg_barColor="#5588FF"
        wheel:matProg_progressIndeterminate="true"  />

    <WebView
        android:id="@+id/webview01"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent">

    </WebView>

</RelativeLayout>

这是代码 -

public class HomeFragment extends Fragment implements OnLongClickListener {

    WebView web; //Defining WebView as web for quick Use :)
    private ProgressWheel progressWheel;//Defining Material-ish Progress as pb for quick Use :)


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) 
    {
        //Inflating the Layout 
        View rootView = inflater.inflate(R.layout.home_fragment, container, false);

        //Finding the Items
        web = (WebView) rootView.findViewById(R.id.webview01);
        progressWheel = (ProgressWheel) rootView.findViewById (R.id.progressBar1);

        //Registering OnLongClick for Image Download
        web.setOnLongClickListener(this);

        //Blog url that is to be loaded
        web.loadUrl("https://lazygeniouz.wordpress.com/");

        //Setting up the WebViewClient
        web.setWebViewClient(new WebViewClient() {

                     //Opens all the Clicked Links in App itself.. (No Opera/Browser/Chrome/Uc popup)
                    @Override
                    public boolean shouldOverrideUrlLoading(WebView view, String url) {
                        view.loadUrl(url);
                        return true;
                    }

                    //Shows a Dialog when there is an Error
                    @Override
                    public void onReceivedError(WebView view, int errorcode,String description, String fallingUrl) {
                        Toast.makeText(getActivity(),"NetWork Error", Toast.LENGTH_SHORT).show();
                    }

                    //Showing ProgressBar when Page is Loading
                    @Override
                    public void onPageStarted(WebView view,String url , Bitmap favicon){
                        progressWheel.setVisibility(View.VISIBLE);
                    }

                    //Hiding ProgressBar when Loading Finished
                    public void onPageFinished(WebView view,String Url){
                        progressWheel.setVisibility(View.GONE);
                    }
                });

        //Setting Up Cookies for the App to remember your Logins
        //Neithee your Id's, Nor Passwords are transferred/submitted anywhere :)
        CookieSyncManager.createInstance(web.getContext());
        CookieSyncManager.getInstance().startSync();
        CookieSyncManager.getInstance();

        //returning the RootView
        return rootView;

}

Styles.xml -

<resources xmlns:tools="http://schemas.android.com/tools">

    <style name="BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/app_primary</item>
        <item name="colorPrimaryDark">@color/app_primary_dark</item>
        <item name="actionBarStyle">@style/ActionBarStyle</item>
    </style>

    <style name="AppTheme" parent="BaseTheme">

    </style>

    <style name="ActionBarStyle" parent="Widget.AppCompat.ActionBar.Solid">
        <item name="elevation">0dp</item>
    </style>

    <style name="MenuLabelsStyle">
        <item name="android:background">@drawable/fab_label_background</item>
        <item name="android:textColor">#FFFFFF</item>
        <item name="android:textSize">14sp</item>
        <item name="android:maxLines">2</item>
        <item name="android:ellipsize">end</item>
    </style>


    <style name="DrawerItemTextAppearance">
        <item name="android:fontFamily" tools:ignore="NewApi">sans-serif-light</item>
    </style>

</resources>

清单 -

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sample" >

    <uses-permission
        android:name="android.permission.INTERNET"/> 
    <uses-permission 
        android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.sample.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>  

 <activity
            android:name="com.sample.AboutAppActivity"
            android:label="AbOuT"/>
    </application>

</manifest>

0 个答案:

没有答案