2011-02-25 85 views
0

我添加了一个自定义标题栏使用下面的代码howeveri似乎有大约10像素左右间距左右2px在底部,是他们无论如何,我可以使自定义标题栏适合titlbar区域?自定义标题栏不填充标题栏区域

感谢您的任何意见

乔纳森

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"?> 

回答

2

你想填补实际标题栏的背景 - 而不是你的自定义区域。 尝试在这里为我工作的解决方案:Set title background color

0

你想使用FILL_PARENT的宽度。在XML:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
+0

对不起,我没有意识到我的布局xml hadnt张贴。我有宽度设置为填写父母 –

+0

我不知道。尝试删除MinWidth和填充? –