Android:我可以更改标题栏位置吗?

发布于 2025-01-05 15:34:29 字数 3279 浏览 6 评论 0原文

我为我的应用程序制作了一个自定义标题栏,但我想看看标题栏位于屏幕底部而不是顶部的外观。可以这样做吗?

非常感谢!

更新:

我正在尝试执行此操作:

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.main);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.headermenu);
    RelativeLayout titleBar = (RelativeLayout) findViewById(R.id.title);
    RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT);
    rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    titleBar.setLayoutParams(rlp);

我的 headermenu.xml 是:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:id="@+id/title" >

        <Button
            android:id="@+id/action_back"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:background="@layout/sendbutton" />

        <Button
            android:id="@+id/action_send"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="1dp"
            android:background="@drawable/ic_menu_send" />

        <Button
            android:id="@+id/action_forward"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:background="@drawable/ic_menu_back" />

        <Button
            android:id="@+id/action_next"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:background="@drawable/ic_menu_forward" />

当 onCreate 函数完成时而不是执行代码时,我收到错误。

错误:

Thread [<1> main] (Suspended (exception ClassCastException))    
    FrameLayout.onLayout(boolean, int, int, int, int) line: 297 
    FrameLayout(View).layout(int, int, int, int) line: 7320 
    LinearLayout.setChildFrame(View, int, int, int, int) line: 1263 
    LinearLayout.layoutVertical() line: 1137    
    LinearLayout.onLayout(boolean, int, int, int, int) line: 1051   
    LinearLayout(View).layout(int, int, int, int) line: 7320    
    PhoneWindow$DecorView(FrameLayout).onLayout(boolean, int, int, int, int) line: 342  
    PhoneWindow$DecorView(View).layout(int, int, int, int) line: 7320   
    ViewRoot.performTraversals() line: 1162 
    ViewRoot.handleMessage(Message) line: 1882  
    ViewRoot(Handler).dispatchMessage(Message) line: 99 
    Looper.loop() line: 130 
    ActivityThread.main(String[]) line: 3701    
    Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
    Method.invoke(Object, Object...) line: 507  
    ZygoteInit$MethodAndArgsCaller.run() line: 866  
    ZygoteInit.main(String[]) line: 624 
    NativeStart.main(String[]) line: not available [native method]  

谢谢!

I have make a custom title bar for my application but I would like to see how it looks with the title bar in the bottom part of the screen instead of top part. Is it posible to do this?

Thank you very much!

Update:

I'm trying to execute this:

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.main);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.headermenu);
    RelativeLayout titleBar = (RelativeLayout) findViewById(R.id.title);
    RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT);
    rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    titleBar.setLayoutParams(rlp);

And my headermenu.xml is:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:id="@+id/title" >

        <Button
            android:id="@+id/action_back"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:background="@layout/sendbutton" />

        <Button
            android:id="@+id/action_send"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="1dp"
            android:background="@drawable/ic_menu_send" />

        <Button
            android:id="@+id/action_forward"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:background="@drawable/ic_menu_back" />

        <Button
            android:id="@+id/action_next"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:background="@drawable/ic_menu_forward" />

I get an error when the onCreate function finishes not when executing the code.

Error:

Thread [<1> main] (Suspended (exception ClassCastException))    
    FrameLayout.onLayout(boolean, int, int, int, int) line: 297 
    FrameLayout(View).layout(int, int, int, int) line: 7320 
    LinearLayout.setChildFrame(View, int, int, int, int) line: 1263 
    LinearLayout.layoutVertical() line: 1137    
    LinearLayout.onLayout(boolean, int, int, int, int) line: 1051   
    LinearLayout(View).layout(int, int, int, int) line: 7320    
    PhoneWindow$DecorView(FrameLayout).onLayout(boolean, int, int, int, int) line: 342  
    PhoneWindow$DecorView(View).layout(int, int, int, int) line: 7320   
    ViewRoot.performTraversals() line: 1162 
    ViewRoot.handleMessage(Message) line: 1882  
    ViewRoot(Handler).dispatchMessage(Message) line: 99 
    Looper.loop() line: 130 
    ActivityThread.main(String[]) line: 3701    
    Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
    Method.invoke(Object, Object...) line: 507  
    ZygoteInit$MethodAndArgsCaller.run() line: 866  
    ZygoteInit.main(String[]) line: 624 
    NativeStart.main(String[]) line: not available [native method]  

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜声 2025-01-12 15:34:29

是的,您可以将标题栏放在 Bottom 布局中

Yes ,You can put in your title bar in Layout in Bottom

注定孤独终老 2025-01-12 15:34:29

将标题栏布局置于底部我将帮助您解决问题

Put titlebar layout to bottom i will help you to solve problem

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文