gpt4 book ai didi

android:在中间设置标题栏

转载 作者:太空狗 更新时间:2023-10-29 15:49:00 25 4
gpt4 key购买 nike

我使用样式创建了自定义标题。我从 http://labs.makemachine.net/2010/03/custom-android-window-title/ 中编写了一些代码

我还使用 setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,R.drawable.title_logo); 设置了标题栏中的图标; 是否可以将标题栏设置在中间?如果可能的话,我想使用自定义样式进行设置。

编辑:我有校验码 http://andmobidev.blogspot.com/2010/01/centering-title-of-window.html 当标题栏中没有图标时它工作正常但是当设置图标时我收到错误 java.lang.ClassCastException: android.widget.RelativeLayout 我不知道窗口是如何绘制标题栏的,我已经查看了博客中的一个 http://android-developers.blogspot.com/2009/03/window-backgrounds-ui-speed.html

谢谢。

最佳答案

我找到了真正的答案,最后我加载了标题栏居中的新布局 在Oncreate中设置标题条码

 final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

setContentView(R.layout.main);
if (customTitleSupported) {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.title_bar);
}
final TextView myTitleText = (TextView) findViewById(R.id.title_bar);
if (myTitleText != null) {
myTitleText.setText(R.string.title_ble_melem);

}

这是布局

<?xml version="1.0" encoding="utf-8" ?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/title_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="title bar"
android:layout_centerInParent="true"
android:layout_marginLeft="5dip"
android:textStyle="bold"
android:textColor="#ffffff"
android:textSize="20sp"
/>

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/title_bar"
android:src="@drawable/ic_top_bar"

/>
</RelativeLayout >

非常感谢您的回复。

关于android:在中间设置标题栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6067490/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com