把Activity的标题栏隐藏有两种方法。一种是在在Activity里面设置javacode。还有一种是在项目的清单文件AndroidManifest.xml中设置模版样式。
一、在Activity中通过javacode代码设置:仅仅须要调用requestWindowFeature()方法,同一时候传递Window.FEATURE_NO_TITLE常量。
public class Activity101Activity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 隐藏当前Activity的标题
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
}
}
需要特别注意的是requestWindowFeature()方法,必需要在setContentView()之前设置。
二、在项目的清单文件AndroidManifest.xml中设置模版样式:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar"> <!--设置整个App的Activity模版样式为:黑底无标题栏-->
<activity
android:name="com.example.intenttest.MainActivity"
android:label="丁超勇"
android:theme="@android:style/Theme.Light.NoTitleBar" <span style="white-space:pre"> </span><!--设置当前Activity的模版样式为:白底无标题栏-->
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
须要特别注意的是在<application>中配置的模版样式在整个App中的每一个Activity都没有标题栏。在<activity>中配置的模版样式仅仅在当前Activity生效。