小编何福毅*_*何福毅的帖子

如何使用rxjava在retrofit 2.0中获取请求URL?

我正在尝试升级到Retrofit 2.0并在我的android项目中添加RxJava.我正在进行api调用,并想要将sqlite中的响应数据作为缓存来检索url和它

Observable<MyResponseObject> apiCall(@Body body);
Run Code Online (Sandbox Code Playgroud)

并在RxJava调用中:

myRetrofitObject.apiCall(body).subscribe(new Subscriber<MyResponseObject>() {
    @Override
    public void onCompleted() {

    }

    @Override
    public void onError(Throwable e) {

    }

    @Override
    public void onNext(MyResponseObject myResponseObject) {

    }
});
Run Code Online (Sandbox Code Playgroud)

在Retrofit 1.9中,我们可以获得成功回调中的url:

        @Override
        public void success(MyResponseObject object, Response response) {
            String url=response.getUrl();
            //save object data and url to sqlite
        }
Run Code Online (Sandbox Code Playgroud)

如何使用RxJava进行Retrofit 2.0?

android rx-java retrofit2

23
推荐指数
1
解决办法
1万
查看次数

在片段中使用 CoordinatorLayout 时如何使状态栏透明

我有一个问题,当我使用包含片段中的图像视图的 CoordinatorLayout 时,我无法使状态栏透明并在状态栏下绘制图像视图(在活动中它没问题)。

为了说明问题,我以cheesesquare为例。

在 cheesesquare 中有一个 CheeseDetailActivity 显示了一些这样的内容(这是我想要的效果):

在活动中 众所周知,在活动中很容易实现这种效果,我拿起关键代码:

  • 样式.xml(v21)

    <资源>

    <style name="Theme.DesignDemo" parent="Base.Theme.DesignDemo"> <item name="android:windowDrawsSystemBarBackgrounds">true <item name="android:statusBarColor">@android:color/transparent</style>

</资源>

  • 活动细节.xml

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginStart="48dp"
        app:expandedTitleMarginEnd="64dp">
    
        <ImageView
            android:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="parallax" />
    
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_collapseMode="pin" />
    
    </android.support.design.widget.CollapsingToolbarLayout>
    
    Run Code Online (Sandbox Code Playgroud)

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingTop="24dp">
    
        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/card_margin">
    
            <LinearLayout
                style="@style/Widget.CardContent"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
    
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Info"
                    android:textAppearance="@style/TextAppearance.AppCompat.Title" />
    
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/cheese_ipsum" />
    
            </LinearLayout>
    
        </android.support.v7.widget.CardView>
    
        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/card_margin"
            android:layout_marginLeft="@dimen/card_margin"
            android:layout_marginRight="@dimen/card_margin"> …
    Run Code Online (Sandbox Code Playgroud)

android android-fragments android-statusbar android-coordinatorlayout

0
推荐指数
1
解决办法
6173
查看次数