android自定义titile

    xiaoxiao2025-07-28  7

    今天做了个自定义title,在这里做一下笔记。

    首先,先把title的布局文件写好,这里需要更具具体是需求。

    <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/gradient_break" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="@string/app_name" android:textSize="18sp" android:textColor="@color/white" /> </RelativeLayout>

    接下了在要设置自定义title的activity的onCreate()方法中添加:

    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.main_title);  //R.layout.main_title是刚刚上面自定义的布局文件。

    好了,自定义title就做好了。

    转载请注明原文地址: https://ju.6miu.com/read-1301141.html
    最新回复(0)