我使用以下代码添加了自定义标题栏。但是,我似乎在底部左右有大约 10 px 间距和 2px,有什么办法可以使自定义标题栏适合标题栏区域?
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.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"?>