今天在看一些源碼的時候,發現人家設定標題都不用樣式布局檔案,看了後感覺還是蠻方便的,
具體操作如下:
super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.share);
添加代碼
requestWindowFeature(Window.FEATURE_NO_TITLE);
設定不要標題,
然後在設定檔添加配置如下:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <RelativeLayout android:id="@+id/rl_top" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" > <TextView android:layout_width="fill_parent" android:layout_height="44dp" android:background="#486a9a" android:gravity="center" android:text="分享例子" android:textColor="@android:color/white" android:textSize="18sp" /> </RelativeLayout> <Button android:id="@+id/share" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="分享" /></LinearLayout>
此操作容易控制,但是布局多的話會寫很多代碼。