0

次のコードを使用してカスタム タイトルバーを追加しました。ただし、左右に約 10 ピクセル、下部に 2 ピクセルの間隔があるようですが、カスタム タイトルバーをタイトルバー領域に合わせる方法はありますか?

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

4

3 に答える 3

2

カスタム領域ではなく、実際のタイトル バーの背景を塗りつぶしたい。ここで解決策を試してみてください:タイトルの背景色を設定する

于 2011-08-14T16:27:20.920 に答える
0

幅にはFILL_PARENTを使用します。XMLの場合:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
于 2011-02-25T05:32:35.213 に答える