且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android:如何在库中正确加载 ViewStub

更新时间:2023-09-30 09:04:16

所以我想回答我的问题给任何一个将来会遇到这个问题的人.

So I want to answer to my question to any one will face this problem in the future.

我只是用 替换了标签 并像这样添加了布局

I just replaced the tag <ViewStub> by <include> and added the layout to it like this

<include
    android:id="@+id/include_action_bar"
    android:layout_width="fill_parent"
    android:layout_height="59dp"
    layout="@layout/actionbar_layout_sml" />

然后我根据我的需要设置可见性(例如对 actionBar):

and then I setup the visibility depending of my needs like this (for example to the actionBar):

public void setActionBarVisibility(boolean visible) {
    View view = findViewById(R.id.include_action_bar);
    if (view != null) {
        if (visible) {
            view.setVisibility(View.VISIBLE);
        }
        else {
            view.setVisibility(View.GONE);
        }
    }
}

希望这对某个地方的某人有所帮助.

Hope this will help someone, somewhere.