gpt4 book ai didi

java - 当我尝试删除 Activity 上的操作栏时,为什么会出现此异常?

转载 作者:行者123 更新时间:2023-12-01 07:55:17 25 4
gpt4 key购买 nike

我正在尝试删除下面的 LoginActivity 上的 ActionBar。我已经实现了 this 中的代码示例代码,但我不希望显示 ActionBar。我没有更改给定的代码,但我真的找不到如何删除 ActionBar(如果可能,如果不只是隐藏它)。

public class LoginActivity extends AppCompatActivity {

// Declaring View and Variables
ViewPager pager;
JoinLoginAdapter adapter;
SlidingTabLayout tabs;
CharSequence Titles[]={"Sign In","Register"};
int Numboftabs = 2;

@Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getSupportActionBar().hide();
super.onCreate(savedInstanceState);
setContentView(R.layout.join_login);

// Creating The ViewPagerAdapter and Passing Fragment Manager, Titles fot the Tabs and Number Of Tabs.
adapter = new JoinLoginAdapter(getSupportFragmentManager(),Titles,Numboftabs);

// Assigning ViewPager View and setting the adapter
pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(adapter);

// Assiging the Sliding Tab Layout View
tabs = (SlidingTabLayout) findViewById(R.id.tabs);
tabs.setDistributeEvenly(true); // To make the Tabs Fixed set this true, This makes the tabs Space Evenly in Available width

// Setting Custom Color for the Scroll bar indicator of the Tab View
tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
@Override
public int getIndicatorColor(int position) {
return getResources().getColor(R.color.tabsScrollColor);
}
});

// Setting the ViewPager For the SlidingTabsLayout
tabs.setViewPager(pager);

}

}

我尝试将 NoTheme 样式应用于 Activity ,但这给了我以下异常:

06-28 01:43:45.615  11537-11537/com.nauv.jambomall E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nauv.jambomall/com.nauv.jambomall.ui.activity.JoinLoginActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2294)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2348)
at android.app.ActivityThread.access$700(ActivityThread.java:159)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5414)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:320)
at com.nauv.jambomall.ui.activity.JoinLoginActivity.onCreate(JoinLoginActivity.java:28)
at android.app.Activity.performCreate(Activity.java:5369)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2348)
at android.app.ActivityThread.access$700(ActivityThread.java:159)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5414) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
at dalvik.system.NativeStart.main(Native Method)

最佳答案

将其放入您的styles.xml

<item name="android:windowActionBar">false</item>

并扩展Activity类而不是AppCompatActivity

关于java - 当我尝试删除 Activity 上的操作栏时,为什么会出现此异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31091705/

25 4 0