2011-02-25 84 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和填充? –