I have added a custom titlebar using the following code. However, I seem to have about 10 px spacing left and right a 2px at the bottom, is there any way I can make the custom titlebar fit the titlebar area?
customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.tab);
        Display display = getWindowManager().getDefaultDisplay(); 
        
        if (customTitleSupported) {
            getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
                            R.layout.titlebar);
            
            LinearLayout titlebar = (LinearLayout) findViewById(R.id.TitleBarLayOut);
            titlebar.setPadding(-2, -1, -2, -1);
            titlebar.setMinimumWidth(display开发者_StackOverflow.getWidth());
            GradientDrawable grad = new GradientDrawable(Orientation.TOP_BOTTOM,
                      new int[] {Color.RED, Color.YELLOW}
                    );
            titlebar.setBackgroundDrawable(grad);
            playButton = new Button(this);
            playButton.setText("Play");
            playButton.setGravity(Gravity.LEFT);
            
            infoButton = new Button( this );
            infoButton.setText("Info");
            infoButton.setGravity(Gravity.RIGHT);
            
            titlebar.addView(playButton, new LinearLayout.LayoutParams(
                      70,1));
            
            titlebar.addView(infoButton, new LinearLayout.LayoutParams(
                  70,1));
            
            
        }
<?xml version="1.0" encoding="utf-8"?>
You want to fill the background of the actual title bar - not your custom area. Try the solution here worked for me: Set title background color
You'd want to use FILL_PARENT for the width. in XML:
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
Today, this is simple as I know in 2011 it wasn't so simple. The property "Dock" set to "Top" would fill it for you.
titlebar.Dock = DockStyle.Top;
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论