2014-12-20 8 views
0

С того дня, когда я пытался показать новую панель действий. Под этим я подразумеваю, что я хочу добавить цвета и новую иконку и т. Д., Но я еще не был успешным. Ниже мой код:Новая панель действий, не показывающая

Manifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.reach2employee" 
android:versionCode="1" 
android:versionName="1.0" > 

<uses-sdk 
    android:minSdkVersion="14" 
    android:targetSdkVersion="21" />   

<uses-permission android:name="android.permission.INTERNET"></uses-permission> 

<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=".RegistrationActivity" 
     android:label="Employer Registration" 
     >    
    </activity> 

    <activity 
     android:name=".LoginActivity" 
     android:label="Employer Login"   
     ></activity> 

    <activity 
     android:name=".ForgotPasswordActivity" 
     android:label="Forgot Password" 
     ></activity> 

    <activity 
     android:name=".PostJobActivity" 
     android:label="Post Job" 
     ></activity> 

    <activity 
     android:name=".SearchJobActivity" 
     android:label="Search Job" 
     ></activity> 

    <activity 
     android:name=".JobsActivity" 
     android:label="All Jobs" 
     ></activity> 

    <activity 
     android:name=".JobDetailActivity" 
     android:label="Job Detail" 
     ></activity> 

</application> 
</manifest> 

menu_before_login.xml

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android" > 

<item 
     android:id="@+id/item1" 
     android:icon="@drawable/ic_action_refresh" 
     android:showAsAction="always" 
     android:title="Refresh" 
></item> 
<item 
     android:id="@+id/item2" 
     android:icon="@drawable/ic_action_overflow" 
     android:showAsAction="always" 
     android:title="Overflow" 
></item> 

</menu> 

MainActivity.xml

package com.reach2employee; 

import android.app.Activity; 
import android.content.Context; 
import android.content.Intent; 
import android.content.SharedPreferences; 
import android.content.SharedPreferences.Editor; 
import android.os.Bundle; 
import android.support.v7.app.ActionBarActivity; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.widget.Button; 

public class MainActivity extends ActionBarActivity {    

Button registerBtn; 
Button loginBtn; 
Button logoutBtn; 
Button shareApp; 

public static final String MyPREFERENCES = Common.myPreferencesStr; 
SharedPreferences sharedpreferences; 
Editor editor; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState);  
    setContentView(R.layout.activity_main);   

    sharedpreferences = getSharedPreferences(MyPREFERENCES,Context.MODE_PRIVATE); 
    editor = sharedpreferences.edit();       

    registerBtn  = (Button)findViewById(R.id.registrationBtn); 
    loginBtn  = (Button)findViewById(R.id.loginBtn);    
    logoutBtn  = (Button)findViewById(R.id.logoutBtn); 
    shareApp  = (Button)findViewById(R.id.shareApp); 

    if(sharedpreferences.contains("userId")){ 
     registerBtn.setVisibility(View.GONE); 
     loginBtn.setVisibility(View.GONE); 
     logoutBtn.setVisibility(View.VISIBLE); 
    } else { 
     registerBtn.setVisibility(View.VISIBLE); 
     loginBtn.setVisibility(View.VISIBLE); 
     logoutBtn.setVisibility(View.GONE); 
    } 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.menu_before_login, menu);  
    return true;   
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 
    if (id == R.id.action_settings) { 
     return true; 
    } 
    return super.onOptionsItemSelected(item); 
} 

public void shareThisAppFun(View view){ 
    Intent sendIntent = new Intent(); 
    sendIntent.setAction(Intent.ACTION_SEND); 
    sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send."); 
    sendIntent.setType("text/plain"); 
    startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.sendThisApp))); 
} 

public void goToRegistrationPage(View view){   
    Common.moveToAnotherActivity(MainActivity.this,RegistrationActivity.class,0); 
} 

public void goToLoginPage(View view){  
    Common.moveToAnotherActivity(MainActivity.this,LoginActivity.class,1); 
} 

public void goToPostAJobActivity(View view){   
    Common.moveToAnotherActivity(MainActivity.this,PostJobActivity.class,1); 
} 

public void goToSearchPage(View view){  
    Common.moveToAnotherActivity(MainActivity.this,SearchJobActivity.class,0); 
} 

public void goToAllJobsPage(View view){ 
    //Common.moveToAnotherActivity(MainActivity.this,JobsActivity.class,0); 

    Intent intent = new Intent(this,JobsActivity.class);   
    intent.putExtra("fromPage", "allJobs");       
    startActivity(intent); 

} 
public void logoutBtnClickFun(View view){ 

    //First clear Session 
    editor.clear(); 
    editor.commit(); 

    Common.moveToAnotherActivity(MainActivity.this,MainActivity.class,1); 
} 
} 

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="fill_parent"  
android:layout_height="fill_parent" 
android:background="#ffffff" 
> 
<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical"  
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.reach2employee.MainActivity" >   
<LinearLayout 
    android:id="@+id/appLogoRow" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"   
    android:orientation="horizontal" 
    >  
    <ImageView 
     android:id="@+id/appLogo" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:contentDescription="@string/app_name" 
     android:src="@drawable/onlyitemployees_logo" 
    />   
</LinearLayout>  
<LinearLayout 
    android:id="@+id/appShortDescRow" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_marginTop="10dp" 
    >     
    <TextView 
     android:id="@+id/appTaglineDesc" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/appTaglineDescStr" 
     android:textSize="18sp" 
     android:textStyle="italic" 
     android:gravity="center" 
     />   
    <TextView 
     android:id="@+id/appShortDesc" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/appShortDesc" 
     android:gravity="center" 
     /> 

    <TextView 
     android:id="@+id/appShortDesc1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/appShortDesc1" 
     android:gravity="center" 
     /> 
    <TextView 
     android:id="@+id/appShortDesc2" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/appShortDesc2" 
     android:gravity="center" 
     /> 

</LinearLayout> 

<LinearLayout 
    android:id="@+id/searchBtnRow" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_marginTop="20dp" 
    > 

    <Button 
     android:id="@+id/shareApp" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/sendThisApp" 
     android:background="#D08B3A" 
     android:textColor="#ffffff" 
     android:onClick="shareThisAppFun"      
    /> 

    <Button 
     android:id="@+id/allJobsBtn" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/allJobsBtnText" 
     android:background="#D08B3A" 
     android:textColor="#ffffff" 
     android:layout_marginTop="10dp" 
     android:onClick="goToAllJobsPage"      
    /> 

    <Button 
     android:id="@+id/searchBtn" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/searchBtnText" 
     android:background="#b93983" 
     android:textColor="#ffffff" 
     android:layout_marginTop="10dp" 
     android:onClick="goToSearchPage"    
     />    

    <Button 
     android:id="@+id/postVacancyBtn" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/postVacancyBtnText" 
     android:background="#9f2c35" 
     android:textColor="#ffffff" 
     android:onClick="goToPostAJobActivity" 
     android:layout_marginTop="10dp" 
    />  

    <Button 
     android:id="@+id/registrationBtn" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/registrationBtnText" 
     android:background="#8eb534" 
     android:textColor="#ffffff" 
     android:layout_marginTop="10dp" 
     android:onClick="goToRegistrationPage" 
    /> 
    <Button 
     android:id="@+id/loginBtn" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/loginBtnText" 
     android:background="#3795BD" 
     android:textColor="#ffffff" 
     android:layout_marginTop="10dp" 
     android:onClick="goToLoginPage" 
    /> 

    <Button 
     android:id="@+id/logoutBtn" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/logoutBtnText" 
     android:background="#3795BD" 
     android:textColor="#ffffff" 
     android:layout_marginTop="10dp" 
     android:onClick="logoutBtnClickFun" 
    /> 

</LinearLayout>  
</LinearLayout> 
</ScrollView> 

styles.xml

<resources> 

<!-- 
    Base application theme, dependent on API level. This theme is replaced 
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices. 
--> 
<style name="AppBaseTheme" parent="Theme.AppCompat.Light"> 
    <!-- 
     Theme customizations available in newer API levels can go in 
     res/values-vXX/styles.xml, while customizations related to 
     backward-compatibility can go here. 
    --> 
</style> 

<!-- Application theme. --> 
<style name="AppTheme" parent="AppBaseTheme"> 
    <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
</style> 

</resources> 

В MainActivity.java, я пытался продлить активность, но это тоже не работает.

+1

В чем ваш вопрос? – rapvelopment

+0

Почему моя обычная или новая панель действий не отображается? – employeegts

+0

Вы никогда не устанавливали панель действий в своем onCreate. Не могли бы вы разместить свой Activity_main.xml? –

ответ

1

Какова Ваша AppTheme? Проверьте в рес/значения/стилей (Android Studio):

<!-- Base application theme. --> 
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar"> 
    <!-- Customize your theme here. --> 
</style> 

Некоторые стили, как показано, включают в себя ActionBar автоматически (даже Расширяет активность). Не уверен, какие другие темы, так как я новичок в Android.

+0

Он создает исключение, показывающее ошибку. – employeegts

+0

Я обновил свой вопрос и добавил в него styles.xml. – employeegts

+0

Думаю, вам придется опубликовать текст ошибки. – wwfloyd

0

Добавить это в menu_before_login.xml файла:

xmlns:app="http://schemas.android.com/apk/res-auto"> 

Вашего файл XML должен выглядеть следующим образом:

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto"> 

</menu> 

Надеется, что это помогает вам.