我正在尝试创建没有操作栏的闪屏。
首先,在创建闪屏之前,主活动中的动作栏,当我创建闪屏时,动作栏出现在闪屏中,主活动是全屏。我搜索了像getwindow(),getActionBar()这样的方法,但是当我使用这些方法时,程序对我说不幸的停止了。那么我错过了什么?
如何在闪屏中避免actionBar?
我的代码:
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_item);
Thread th=new Thread(){
public void run(){
try {
sleep(4000);
Intent intent=new Intent(MainActivity.this,SplashScreen.class);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
finally{
finish();
}
}
};
th.start();
}MANİFEST:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SplashScreen"
android:label="@string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.SPLASHSCREEN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>发布于 2015-01-29 06:42:24
首先,在你的应用顶部导入支持库:
import android.support.v7.app.ActionBarActivity;并按如下方式更改代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_item);
getSupportActionBar().hide();
}发布于 2016-01-13 01:33:17
使用所有版本都支持的AppCompat:
<activity
android:theme="@style/Theme.AppCompat.Light.NoActionBar">发布于 2015-01-29 05:49:01
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);把它放在你的setContentView(...)之前,应该能完成工作。
https://stackoverflow.com/questions/28202916
复制相似问题