Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问activity可以像fragment那样把title放出来么 #62

Closed
liguangze opened this issue Nov 13, 2017 · 8 comments
Closed

请问activity可以像fragment那样把title放出来么 #62

liguangze opened this issue Nov 13, 2017 · 8 comments

Comments

@liguangze
Copy link

liguangze commented Nov 13, 2017

您当时说抽出来放在基类,是可以实现,但是我的基类里面已经有这些方法了,有的时候,动态添加View,太容易报错了,出现异常,有没有别的办法实现呢,简单点的,
有些地方我的最外层布局是一些特殊的布局,
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT);

您这个方法又强制的改了我的最外层布局,我不想改布局呢

@KingJA
Copy link
Owner

KingJA commented Nov 14, 2017

@liguangze 请问你使用的是哪个版本?动态添加View出异常能不能详细描述下?

@liguangze
Copy link
Author

1.30,我没有使用这种方式,因为不想改变我的基类,且在基类中动态添加,还有不想改最外层布局,没有出现异常,就是感觉会容易出现,有没有什么比较简单的实现方式

@KingJA
Copy link
Owner

KingJA commented Nov 14, 2017

@liguangze 不知道你有没参考过v1.3.2 Demo中的KeepTitleActivity,把Title的设置抽取到基类BaseTitleActivity中,由子类去实现。

@liguangze
Copy link
Author

我看到了,我发现一个留头的好实现方式了,
loadService = LoadSir.getDefault().register(this, new Callback.OnReloadListener() {
@OverRide
public void onReload(View v) {
//网络错误后,点击重新加载逻辑
}
});

里面的参数第一个参数传的是this,我发现不传this,布局的父布局,这样就不会把头隐藏了
这是我的xml

<include layout="@layout/item_toolbar_layout" />

<com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout

    android:id="@+id/swipeRefreshLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
    android:id="@+id/hot_book_list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="none">
</android.support.v7.widget.RecyclerView>
</com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout>

只要是把swipeRefreshLayout这个id传过去,不传this,这样可以很好的保留activity的title,比抽取基类要简单的多,

@KingJA
Copy link
Owner

KingJA commented Nov 14, 2017

@liguangze 这就是类似View的注册方式啊,好吧,你成功地带我饶了一圈。

@KingJA KingJA closed this as completed Nov 14, 2017
@liguangze
Copy link
Author

不是的,我遇到的问题是留title,不是注册的方式,但是我稍微给了下你的源码,已经解决了,activity中不用再基类中就可以显示title了

@NicodeLee
Copy link

NicodeLee commented Dec 8, 2017

@liguangze 这样还是要多写代码。
@KingJA K 看了demo BaseTitleActivity.java,这样虽然好,不过如果是后期要加入需要改动的也不少。
比如内容view要统一加id fl_content ,子act布局去掉标题布局,改统一在基类加,还要处理有标题跟无标题的情况。

@KingJA
Copy link
Owner

KingJA commented Dec 9, 2017

@liguangze fl_content 是抽象到父类的内容布局,子类只要去实现自己的布局即可。关于标题栏的所有设置都可以抽取到父类,BaseTitleActivity适用于需要标题栏的Activity,如果你不需要标题栏或者自定义复杂标题栏可以直接实现或继承别的父类。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants