1. 讓textView里面的內容水平居中 : android:gravity="center_horizontal"
2. 讓textView控件在它的父布局里水平居中 android:layout_gravity="center_horizontal"
現在我堅定的認為寫技術博客對自己有很大的幫助,寫博客給自己一個學而思的機會。
在android中去掉標題欄有三種方法,它們也有各自的特點。
1.在代碼里實現
- this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉標題欄
this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉標題欄
記住:這句代碼要寫在setContentView()前面。
2.在清單文件(manifest.xml)里面實現
- <application android:icon="@drawable/icon"
- android:label="@string/app_name"
- android:theme="@android:style/Theme.NoTitleBar">
<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar">
這樣用可以將整個應用設置成無標題欄,如果只需要在一個Activity設置成一個無標題欄的形式,只要把上面的第三行代碼寫到某一個Activity里面就可以了。
3.在style.xml文件里定義
- <?xml version="1.0" encoding="UTF-8" ?>
- <resources>
- <style name="notitle">
- <item name="android:windowNoTitle">true</item>
- </style>
- </resources>
<?xml version="1.0" encoding="UTF-8" ?> <resources> <style name="notitle"> <item name="android:windowNoTitle">true</item> </style> </resources>
然后面manifest.xml中引用就可以了,這種方法稍麻煩了些。
- <application android:icon="@drawable/icon"
- android:label="@string/app_name"
- android:theme="@style/notitle">
<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/notitle">
其實可以看得出來,第二種方法和第三種方法實質是一樣的,只不過第二種方法調用的是系統定義好的style.xml文件,而第三種方法則是在自己的應用里定義style.xml,然后再自己再調用,其實道理是一樣的,第三種方法做起來更有成就感。