没有填充自定义标题栏(安卓) [英] Custom title bar without padding (Android)

查看:142
本文介绍了没有填充自定义标题栏(安卓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我现在用的技术,这个线程使用自定义的背景为我的标题栏。不幸的是,框架放在我的布局在<$​​ C $ C>的FrameLayout ( title_container ),其中有填充,如下图所示。

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.

反正是有删除灰边框?框架布局在<$​​ C $ C> com.android.internal.R.id.title_container 定义,因此访问帧通过ID将是脆弱的。

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.

推荐答案

我挣扎与此相同的问题,我现在有答案了!

I was struggling with this same issue and now I have the answer!

正如你可能已经看到了几个地方,你需要创建的themes.xml资源:

As you probably have seen several places, you need to create a themes.xml resource:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyTheme" parent="android:Theme">
            <item name="android:windowTitleSize">44dip</item>
            <item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground</item>
    </style>
</resources>

请注意它是不是经常在你需要选择这个主题的观点,活动或应用程序级的网站上谈论有关自定义标题栏提及。我这样做是在应用层通过增加安卓主题属性到应用程序:

Note it is not often mentioned in the sites talking about custom title bars you need to select this theme at the view, activity, or application level. I do it at the application level by adding android:theme property to the application:

  <application android:icon="@drawable/icon"
               android:label="@string/app_name"
               android:theme="@style/MyTheme">

您还需要一个styles.xml定义WindowTitleBackgroundStyle。不同的是各种版本的这个文件我已经看到漂浮aroung网络的,我已经增加了一个额外的线路,设置填充为0,摆脱你都在抱怨填充的文件:

You also need a styles.xml to define that WindowTitleBackgroundStyle. Unlike the various versions of this file I have seen floating aroung the web, I have added one additional line to the file that sets the padding to 0 which gets rid of the padding you are complaining about:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <style name="WindowTitleBackground">
        <item name="android:background">@android:color/transparent</item>
        <item name="android:padding">0px</item>
    </style>
</resources>

这篇关于没有填充自定义标题栏(安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆