我的 android 应用程序的登录页面上有一个 DrawingLayout。我想让它在整个应用程序中可见,以便我可以将它用作我的应用程序的导航控件。可能吗?如果是,我该如何实现?
提前非常感谢。
我的 android 应用程序的登录页面上有一个 DrawingLayout。我想让它在整个应用程序中可见,以便我可以将它用作我的应用程序的导航控件。可能吗?如果是,我该如何实现?
提前非常感谢。
把你DrawingLayout
的每一个活动。
创建一个返回线性布局的类,其中包含您想要在应用程序屏幕上的所有导航控件,并通过方法 addView(lin_layout) 将其添加到您的活动中;
看这个
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;
}
您可以通过以下方式将此导航栏添加到您的活动中
yourClass toolbar = new yourClass();
LinearLayout topBar = toolbar.createNavBar(72,"your title", mContext);
this.addView(topBar);