Android 我的应用程序赢了';不要显示操作栏

Android 我的应用程序赢了';不要显示操作栏,android,android-actionbar,android-theme,Android,Android Actionbar,Android Theme,我试图在我的一项活动上显示一个操作栏,但我似乎不明白为什么它不会显示。 有人能帮忙吗 活动: public class Login extends Activity { public static final String TAG = "MainActivity"; public static final String DEFAULT_CHAT_NAME = ""; private WifiP2pManager mManager; private Chan

我试图在我的一项活动上显示一个操作栏,但我似乎不明白为什么它不会显示。
有人能帮忙吗

活动:

public class Login extends Activity {
    public static final String TAG = "MainActivity";    
    public static final String DEFAULT_CHAT_NAME = "";
    private WifiP2pManager mManager;
    private Channel mChannel;
    private WifiDirectBroadcastReceiver mReceiver;
    private IntentFilter mIntentFilter;
    private com.ajapps.app.floatingactionbutton.AddFloatingActionButton goToChat;
    private ImageView goToSettings;
    private TextView goToSettingsText;
    private TextView setChatNameLabel;
    private EditText setChatName;
    private ImageView disconnect;
    public static String chatName;
    public static ServerInit server;

    //Getters and Setters
    public WifiP2pManager getmManager() { return mManager; }
    public Channel getmChannel() { return mChannel; }
    public WifiDirectBroadcastReceiver getmReceiver() { return mReceiver; }
    public IntentFilter getmIntentFilter() { return mIntentFilter; }
    public com.ajapps.app.floatingactionbutton.AddFloatingActionButton getGoToChat(){ return goToChat; }
    public TextView getSetChatNameLabel() { return setChatNameLabel; }
    public ImageView getGoToSettings() { return goToSettings; }
    public EditText getSetChatName() { return setChatName; }
    public TextView getGoToSettingsText() { return goToSettingsText; }
    public ImageView getDisconnect() { return disconnect; }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);

        //Init the Channel, Intent filter and Broadcast receiver
        init();

        //Button Go to Settings
        goToSettings = (ImageView) findViewById(R.id.goToSettings);
        goToSettings();

        //Go to Settings text
        goToSettingsText = (TextView) findViewById(R.id.textGoToSettings);

        //Button Go to Chat
        goToChat = (com.ajapps.app.floatingactionbutton.AddFloatingActionButton) findViewById(R.id.goToChat);
        goToChat();

        //Set the chat name
        setChatName = (EditText) findViewById(R.id.setChatName);
        setChatNameLabel = (TextView) findViewById(R.id.setChatNameLabel);
        setChatName.setText(loadChatName(this));

        //Button Disconnect
        disconnect = (ImageView) findViewById(R.id.disconnect);
        disconnect();
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
    }

    @Override
    public void onResume() {
        super.onResume();
        registerReceiver(mReceiver, mIntentFilter);

        mManager.discoverPeers(mChannel, new WifiP2pManager.ActionListener() {

            @Override
            public void onSuccess() {
                Log.v(TAG, "Discovery process succeeded");
            }

            @Override
            public void onFailure(int reason) {
                Log.v(TAG, "Discovery process failed");
            }
        });
    }

    @Override
    public void onPause() {
        super.onPause();
        unregisterReceiver(mReceiver);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
//        int idItem = item.getItemId();
        return super.onOptionsItemSelected(item);
    }

    public void init(){
        mManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
        mChannel = mManager.initialize(this, getMainLooper(), null);
        mReceiver = WifiDirectBroadcastReceiver.createInstance();
        mReceiver.setmManager(mManager);
        mReceiver.setmChannel(mChannel);
        mReceiver.setmActivity(this);

        mIntentFilter = new IntentFilter();
        mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
        mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
        mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
        mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
    }

    public void goToChat(){
        goToChat.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                if(!setChatName.getText().toString().equals("")){
                    //Set the chat name
                    saveChatName(Login.this, setChatName.getText().toString());
                    chatName = loadChatName(Login.this);

                    //Start the init process
                    if(mReceiver.isGroupeOwner() ==  WifiDirectBroadcastReceiver.IS_OWNER){
                        Toast.makeText(Login.this, "I'm the group owner  " + mReceiver.getOwnerAddr().getHostAddress(), Toast.LENGTH_SHORT).show();
                        server = new ServerInit();
                        server.start();
                    }
                    else if(mReceiver.isGroupeOwner() ==  WifiDirectBroadcastReceiver.IS_CLIENT){
                        Toast.makeText(Login.this, "I'm the client", Toast.LENGTH_SHORT).show();
                        ClientInit client = new ClientInit(mReceiver.getOwnerAddr());
                        client.start();
                    }

                    //Open the ChatActivity
                    Intent intent = new Intent(getApplicationContext(), ChatActivity.class);
                    startActivity(intent);
                }
                else{
                    Toast.makeText(Login.this, "Please enter a chat name", Toast.LENGTH_SHORT).show();
                }                   
            }
        });     
    }

    public void disconnect(){
        disconnect.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                mManager.removeGroup(mChannel, null);
                finish();
            }
        });     
    }

    public void goToSettings(){     
        goToSettings.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                //Open Wifi settings
                startActivityForResult(new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS), 0);
            }
        });     
    }

    //Save the chat name to SharedPreferences
    public void saveChatName(Context context, String chatName) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        Editor edit = prefs.edit();
        edit.putString("chatName", chatName);
        edit.commit();
    }

    //Retrieve the chat name from SharedPreferences
    public String loadChatName(Context context) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        return prefs.getString("chatName", DEFAULT_CHAT_NAME);
    }
}
和我的xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.ajapps.wifichat.MainActivity">

    <!-- Go to Settings screen -->

    <LinearLayout 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:id="@+id/linearLayout"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true">

        <ImageView 
            android:id="@+id/goToSettings"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/go_to_settings_button"
            android:src="@drawable/wifi_icon"
            android:layout_gravity="center" />

        <TextView
            android:id="@+id/textGoToSettings"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:text="@string/go_to_settings_text"
            android:textSize="16sp"
            android:textColor="@color/red"
            android:gravity="center"
            android:layout_gravity="center_vertical"/>

    </LinearLayout>


    <!-- Go to Chat screen -->

    <ImageView 
        android:id="@+id/disconnect"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/setChatNameLabel"
        android:contentDescription="@string/disconnect"
        android:src="@drawable/disconnect"
        android:layout_marginBottom="15dp"
        android:visibility="gone"
        android:layout_centerHorizontal="true"/>

    <TextView 
        android:id="@id/setChatNameLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/setChatName"
        android:text="@string/set_chat_name"
        android:layout_centerHorizontal="true"
        android:textSize="18sp"
        android:textColor="@color/app_text"
        android:visibility="gone" />

    <com.ajapps.app.floatingactionbutton.AddFloatingActionButton
        android:id="@+id/goToChat"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        fab:fab_icon="@drawable/send"
        android:background="@drawable/button_pressed2"
        fab:fab_plusIconColor="@color/half_black"
        fab:fab_colorNormal="@color/red"
        fab:fab_colorPressed="@color/red_pressed"
        android:layout_centerVertical="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:visibility="gone" />

    <EditText
        android:id="@+id/setChatName"
        android:inputType="textCapWords"
        android:lines="1"
        android:maxLength="20"
        android:layout_width="160dp"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@drawable/edit_text"
        android:layout_marginTop="15dp"
        android:visibility="gone" />

</RelativeLayout>

原因如下:
公共类登录扩展活动{

你必须从一开始就扩展


不是ActionBarActivity,因为它是。

原因如下:
公共类登录扩展活动{

你必须从一开始就扩展

不是ActionBarActivity,因为它是。

只需更改即可

   public class Login extends Activity {

   }
   public class Login extends AppCompatActivity {
   }
换衣服

   public class Login extends Activity {

   }
   public class Login extends AppCompatActivity {
   }

你确定你没有使用.NoActionBar主题吗?请查看我的更新,我包括了我的theme@FrankN.Stein它不允许我扩展到这一点,所以我将它扩展到了ActionBarActivity,它起了作用。感谢ActionBarActivity。你确定你没有使用.NoActionBar主题吗?请查看我的更新,我包括了我的theme@FrankN.stein它不允许我扩展到这一点,所以我将它扩展到了ActionBarActivity,它起了作用,感谢ActionBarActivity