Android的不能删除各地自定义标题栏填充自定义、标题栏、Android

由网友(今年流行自作多情)分享简介:我添加自定义IMG的头冠军,但无论我做什么,我仍然对IMG的每一面小的差距(也显示在此question)下面是我的strings.xml文件中的XML <?XML版本=1.0编码=UTF-8&GT?;<资源>    <字符串名称=你好>< /串>    <字符串名称=A...

我添加自定义IMG的头冠军,但无论我做什么,我仍然对IMG的每一面小的差距(也显示在此question)

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

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

下面是我的活动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(假); 
CAD出图技巧 自定义设置布局

解决方案

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

 私人无效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);
}

阅读全文

相关推荐

最新文章