Android的不能删除各地自定义标题栏填充 [英] Android can't remove padding around custom title bar

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

问题描述

我添加自定义IMG的头冠军,但无论我做什么,我仍然对IMG的每一面小的差距(也显示在此<一个href=\"http://stackoverflow.com/questions/2665507/custom-title-bar-without-padding-android\">question)

下面是我的strings.xml文件中的XML

 &LT;?XML版本=1.0编码=UTF-8&GT?;
&LT;资源&GT;
    &LT;字符串名称=你好&GT;&LT; /串&GT;
    &LT;字符串名称=APP_NAME&GT;&LT; /串&GT;
    &LT;样式名称=LargeTitleTheme父=机器人:Theme.Light&GT;
        &LT;项目名称=机器人:windowTitleSize&GT; 44dip&LT; /项目&GT;
    &LT; /风格&GT;
&LT; /资源&GT;

下面是我的活动code(忽略斜率 - 绝望的编码在这一点上)

 的ViewGroup decorView =(ViewGroup中)this.getWindow()getDecorView();
    的LinearLayout根=(的LinearLayout)decorView.getChildAt(0);
    的FrameLayout titleContainer =(的FrameLayout)root.getChildAt(0);
    TextView的标题=(TextView中)titleContainer.getChildAt(0);
    title.setGravity(Gravity.CENTER);
    可绘制可绘制= getResources()getDrawable(R.drawable.nav)。
    drawable.setBounds(0,0,0,0);
    title.setBackgroundDrawable(绘制);
    (0,0,0,0)title.setPadding;
    title.setIncludeFontPadding(假);


解决方案

原来我不得不修改标题容器本身的背景色:)

 私人无效setNavigationAndTitle(){
        的setTitle(随机标题);
        ViewGroup中decorView =(ViewGroup中)this.getWindow()getDecorView()。
        的LinearLayout根=(的LinearLayout)decorView.getChildAt(0);
        的FrameLayout titleContainer =(的FrameLayout)root.getChildAt(0);
        titleContainer.setBackgroundColor(Color.BLUE);
        TextView的标题=(TextView中)titleContainer.getChildAt(0);
        title.setTextSize(20);
        title.setGravity(Gravity.CENTER);
        title.setBackgroundColor(Color.BLUE);
}

I'm adding a custom img to the header title but no matter what I do I still have a small gap on each side of the img (also shown in this question)

Here is the xml in my strings.xml file

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello"></string>
    <string name="app_name"></string>
    <style name="LargeTitleTheme" parent="android:Theme.Light">
        <item name="android:windowTitleSize">44dip</item>
    </style>
</resources>

Here is the code in my activity (ignore the slop - desperate coding at this point)

ViewGroup decorView = (ViewGroup) this.getWindow().getDecorView();
    LinearLayout root = (LinearLayout) decorView.getChildAt(0);
    FrameLayout titleContainer = (FrameLayout) root.getChildAt(0);
    TextView title = (TextView) titleContainer.getChildAt(0);
    title.setGravity(Gravity.CENTER);
    Drawable drawable = getResources().getDrawable(R.drawable.nav);
    drawable.setBounds(0,0,0,0);
    title.setBackgroundDrawable(drawable);
    title.setPadding(0,0,0,0);
    title.setIncludeFontPadding(false);

解决方案

It turns out I had to modify the background color of the title container itself :)

private void setNavigationAndTitle() {
        setTitle("Random Title");
        ViewGroup decorView = (ViewGroup) this.getWindow().getDecorView();
        LinearLayout root = (LinearLayout) decorView.getChildAt(0);
        FrameLayout titleContainer = (FrameLayout) root.getChildAt(0);
        titleContainer.setBackgroundColor(Color.BLUE);
        TextView title = (TextView) titleContainer.getChildAt(0);
        title.setTextSize(20);
        title.setGravity(Gravity.CENTER);
        title.setBackgroundColor(Color.BLUE);
}

这篇关于Android的不能删除各地自定义标题栏填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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