Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 导航抽屉扩展基本活动_Android_User Interface - Fatal编程技术网

Android 导航抽屉扩展基本活动

Android 导航抽屉扩展基本活动,android,user-interface,Android,User Interface,我已经创建了一个带有导航抽屉和searchview的baseactivity。我试图在其他活动中扩展这一点,但也有不同的内容。但是,如果我扩展基本活动,并尝试设置不同的内容视图,则无法获得导航抽屉/搜索视图 如何扩展baseactivity,但仍然为每个活动自定义ui 谢谢你的帮助 最好的方法是使用片段。但是,要使用多个活动,请扩展基本活动,然后在该活动的布局中使用setContentView。确保该布局的xml也包含导航抽屉布局 听起来你想做这样的事情。您将看到,继承自此活动并调用setCon

我已经创建了一个带有导航抽屉和searchview的baseactivity。我试图在其他活动中扩展这一点,但也有不同的内容。但是,如果我扩展基本活动,并尝试设置不同的内容视图,则无法获得导航抽屉/搜索视图

如何扩展baseactivity,但仍然为每个活动自定义ui


谢谢你的帮助

最好的方法是使用片段。但是,要使用多个活动,请扩展基本活动,然后在该活动的布局中使用setContentView。确保该布局的xml也包含导航抽屉布局

听起来你想做这样的事情。您将看到,继承自此活动并调用setContentView的任何活动现在都会将其内容添加到已经膨胀的导航布局中的内容框架中

public class BaseActivity extends FragmentActivity
{
    private FrameLayout mContentFrame;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        // notice we call super.setContentView here
        super.setContentView(R.layout.activity_main);

        // and other nav stuff here

        mContentFrame = findViewById(R.id.content_frame);
    }

    @Override
    public void setContentView(int layoutResID)
    {
        setContentView(getLayoutInflater().inflate(layoutResID, mContentFrame, false));
    }

    @Override
    public void setContentView(View view)
    {
        mContentFrame.removeAllViews();
        mContentFrame.addView(view);
    }

    @Override
    public void setContentView(View view, LayoutParams params)
    {
        mContentFrame.removeAllViews();
        addContentView(view, params);
    }

    @Override
    public void addContentView(View view, LayoutParams params)
    {
        mContentFrame.addView(view, params);
    }
}

谢谢你的回复!当我扩展基本活动和setContentView时,我的活动无法完全工作,我只需复制代码即可获得导航抽屉到工作抽屉中的显示选项,使用主页按钮等。扩展活动会带来什么好处?您能告诉我们您创建的基类吗?