简体   繁体   English

如何使Android视图在整个应用程序中可见?

[英]How to make an android view visible across the application?

I have a DrawingLayout on my android app's landing page. 我的Android应用程式到达网页上有一个DrawingLayout。 I want to make it visible throughout the application so that I can use that as navigation control for my app. 我想使其在整个应用程序中可见,以便可以将其用作应用程序的导航控件。 Is it possible? 可能吗? If Yes, how can I achieve that? 如果是,我该如何实现?

Thanks a lot in advance. 非常感谢。

将您的DrawingLayout放在每个活动中。

create a class which return a Linear layout containing all your navigation controls which you want on your application screens and add that to your activity by method addView(lin_layout); 创建一个返回线性布局的类,其中包含您想要在应用程序屏幕上显示的所有导航控件,并通过方法addView(lin_layout)将其添加到您的活动中;

look at this 看这个

    public class yourClass{
        Context context;
        public LinearLayout createNavBar(int tooBarHeight,String mTitle, Context mContext)
        {

           LinearLayout topBar = new LinearLayout(mContext);
            topBar.setGravity(Gravity.TOP);
            topBar.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,tooBarHeight));   
            topBar.setBackgroundDrawable(d);

            TextView text = new TextView(mContext);
            text.setLayoutParams(new LayoutParams(width - 2*tooBarHeight,tooBarHeight));
            text.setGravity(Gravity.CENTER_VERTICAL);
            text.setText(mTitle);
            text.setTextColor(Color.WHITE);
            text.setPadding(15, 10, 0, 0);
            text.setTextSize(18);

            topBar.addView(text);

            Button home = new Button(mContext);
            home.setLayoutParams(new LayoutParams(tooBarHeight,LayoutParams.MATCH_PARENT));
            //home.setPadding(15, 15, 15, 15);
            home.setGravity(Gravity.RIGHT & Gravity.CENTER_VERTICAL);
            topBar.addView(home);

            home.setOnClickListener(new View.OnClickListener() {

            });

            Button order = new Button(mContext);
            order.setLayoutParams(new LayoutParams(tooBarHeight,LayoutParams.MATCH_PARENT));    
            order.setGravity(Gravity.RIGHT & Gravity.CENTER_VERTICAL);
            //order.setPadding(15, 15, 15, 15); 
            topBar.addView(order);

            order.setOnClickListener(new View.OnClickListener() {

            });

            return topBar;  
       }

} you can add this nav bar to your activity by }您可以通过以下方式将此导航栏添加到您的活动中:

yourClass toolbar = new yourClass();
            LinearLayout topBar  = toolbar.createNavBar(72,"your title", mContext);         
            this.addView(topBar);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使视图仅对 recyclerview android 中单击的项目可见 - How to make view visible to only the item clicked in recyclerview android 如何在Android的keyBoard隐藏事件中显示View(spinner)? - How to make a View(spinner) visible on keyBoard hide event in Android? 如何使视图不占用任何空间,但在Android RecyclerView中仍然可见? - How to make view not to take any space but still be visible in Android RecyclerView? 如何在Android中滑动动画并使视图从右向左可见 - How to slide animate and make a view visible from right to left in Android 如何使回收站视图始终可见,即使是空的 - Android - How to make recycler view always visible even empty - Android 如何在android应用程序中始终可见或显示缩放控制按钮? - How to make visible or display Zoom control buttons always in android application? 在 Android 应用程序中,如何使用透明文本制作线性视图,以便父视图可见? - In an Android app, how do I make a linear view with transparent text so that the parent view is visible? 如何使按钮在可扩展文本视图中可见 - How to make button visible in expandable text view 如何使视图可见并带有一些动画? - how to make view visible and gone with some animation? 如何使我的应用程序在所有设备上可见? - How to make my application visible for all devices?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM