Android 从xml向标题栏添加按钮
我对标题栏有问题。我想在标题栏上做两个按钮,但是看起来很糟糕。首先我想我的按钮高度太大了,但是当我改变按钮高度时,什么都没有改变。我不想要自定义标题栏,也看不到按钮中的文本。有人能帮我吗Android 从xml向标题栏添加按钮,android,android-layout,uibutton,Android,Android Layout,Uibutton,我对标题栏有问题。我想在标题栏上做两个按钮,但是看起来很糟糕。首先我想我的按钮高度太大了,但是当我改变按钮高度时,什么都没有改变。我不想要自定义标题栏,也看不到按钮中的文本。有人能帮我吗 我的代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:la
我的代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/titleLayout">
<Button android:id="@+id/done"
android:layout_width="60dip"
android:layout_height="38dip"
android:text="done"
android:layout_toRightOf="@+id/edit"
>
</Button>
<Button android:id="@+id/edit"
android:layout_width="60dip"
android:layout_height="38dip"
android:text="edit"
>
</Button>
</RelativeLayout>
code nippet:
final boolean customTitle = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
if ( customTitle ) { Window win = getWindow();
win.setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.title);
代码nippet:
最终布尔值customTitle=requestWindowFeature(Window.FEATURE\u CUSTOM\u TITLE);
如果(customTitle){Window win=getWindow();
win.setFeatureInt(窗口.功能\自定义\标题,R.layout.标题);
js但是试着让你的相对化你的的高度包裹内容你可以这样做。在初始化setContentView()之前,写下这行代码
requestWindowFeature(Window.FEATURE_NO_TITLE);
然后在布局XML文件中,像这样包含自定义标题栏
<include layout="@layout/title" android:id="@+id/title"/>
如何使用文本并格式化背景、边缘等,使其看起来像一个按钮。我会尝试使用文本视图,包装内容,然后播放填充和背景
然后在@drawable/bluebutton.xml中
查看此链接了解更多详细信息,我希望它有帮助。。。
您是否尝试使用不固定大小的按钮,而是使用包装内容
而不是?能否给出一个代码段,将布局设置为标题?当然可以。我的xml文件名是标题。我用以下代码调用我的代码:final boolean customTitle=requestWindowFeature(Window.FEATURE\u CUSTOM\u title);if(customTitle){Window win=getWindow();win.setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.TITLE);}如果您添加此片段,对每个人都会更好,因为您的帖子的版本看起来标题栏大小是固定的,并且不会因栏的内容而改变。我该怎么办?您有什么建议吗?定义两个自己的XML,其中一个应该来自android:Theme.Light.NoTitleBar
,另一个来自android:WindowTitleBackground
并应用它们:首先是你的标题,其次是你想成为你的自定义标题的布局Bari不想自定义标题栏。为什么不能添加好看的按钮?如果我们可以添加,我们可以做好看的,我想。但我真的非常感谢回复@teoRetikIf你会看到Android源代码,只有一个Window
class-PhoneWindow
的实现,只有这个类正确使用了setFeatureInt
。其他类只会扩大标题空间,但不确定其大小。
<RelativeLayout xmlns:android=" http://schemas.android.com/apk/res/android "
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/titleLayout">
<TextView
android:id="@+id/doneBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:background="@drawable/bluebutton"
android:text="Done"
android:textStyle="bold"
android:textColor="#FFFFFFFF"
/>
</RelativeLayout>
and then in your @drawable/bluebutton.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android=" http://schemas.android.com/apk/res/android ">
<item>
<shape>
<gradient
android:startColor="#FFBBDDFF"
android:centerColor="#FF191990"
android:endColor="#FF0000FF"
android:angle="270" />
</shape>
</item>
</selector>