[英]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.