繁体   English   中英

自定义标题栏中的问题(android)

[英]issue in custom title bar (android)

当我通过添加图像在视图中自定义标题栏时,我面临一个问题,因为图像没有准确地固定到边缘。 我已经附加了图像,您可以在其中看到窗口边距和添加的图像之间的空间。 如何克服这个问题。 下面是我用来自定义标题栏的代码。 任何人都可以帮我解决这个问题。

java代码:

 requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
 setContentView(R.layout.home_view);
 this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
            R.layout.upwindow);

布局代码:

  <?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    
  android:orientation="vertical" 
   android:layout_width="fill_parent"
     android:layout_height="32dp">

     <ImageView
         android:id="@+id/imageView1"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:background="@drawable/up_bar"
         android:src="@drawable/up_bar" />

<TextView 
    android:id="@+id/pagename"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:text="Sify MyStorage"
    android:textAppearance="?android:attr/textAppearanceMedium" />

</RelativeLayout>

在此输入图像描述

你有不同分辨率的不同图像吗? 可能是您的图像不适合该空间,并且您需要更大的图像。 但要小心,您可能会遇到使用缩放功能在不同平台上工作的问题。

在values文件夹中创建样式xml:

<resources>
  <style name="CustomWindowTitleBackground" /> 
  <style name="CustomTheme" parent="android:Theme">
  <item name="android:windowTitleSize">32dp</item> 
 <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground
 </item> 

</style>
</resources>

然后在清单中将其引用为:

 android:theme="@style/CustomTheme">

这将解决它。

希望这个帮助。

您需要使用样式进行一些操作才能覆盖此行为。 定义自定义主题(样式),如下所示:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="customTitle">
        <item name="android:background">@drawable/up_bar</item>
    </style>
    <style name="myTheme" parent="android:Theme"> 
        <item name="android:windowTitleBackgroundStyle">@style/customTitle</item>
    </style>
</resources>

然后在AndroidManifest.xml中将android:theme="@style/myTheme"到您想要的活动标签,从而在您的活动中使用此主题

requestWindowFeature(Window.FEATURE_NO_TITLE);

和setBackground到布局文件中的布局......

喜欢,,,

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    
  android:orientation="vertical"  
   android:layout_width="fill_parent"  android:background="@drawable/up_bar" <---Add this
     android:layout_height="32dp">

Remove imageview from xml

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM