Custom title bar without padding (Android)

2020-01-27 04:39发布

So I am using the techniques in this thread to use a custom background for my titlebar. Unfortunately the framework places my layout inside a FrameLayout (title_container) which has padding as seen below.

alt text
(source: ggpht.com)

Is there anyway to remove the grey borders? The frame layout is defined in com.android.internal.R.id.title_container, so accessing the frame by ID would be fragile.

7条回答
迷人小祖宗
2楼-- · 2020-01-27 05:29

I got rid of the padding by getting the title container and setting the padding to 0. It works on Android 4.

titleContainerId = (Integer)Class.forName("com.android.internal.R$id").getField("title_container").get(null);

ViewGroup vg = ((ViewGroup) getWindow().findViewById(titleContainerId));
vg.setPadding(0, 0, 0, 0);
查看更多
登录 后发表回答