employeegts employeegts - 1 month ago 11
Android Question

Action bar not showing on new activity

Action bar on new activities are not showing. I spent couple of hours on stack over flow and other websites on finding what can be the reason but i could not figure out the problem.

Can you please tell me what can be the reason and what will be the possible solution?

Following is my code

First i created : activity_forgot_password.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="match_parent"
android:layout_height="match_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.ForgotPasswordActivity"
>

<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"
/>

<TextView
android:id="@+id/forgotPasswordTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/forgotPasswordBtnText"
android:textColor="#D08B3A"
android:layout_marginTop="15dp"
/>

<EditText
android:id="@+id/employerUsername"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/employerUsernameHint"
android:layout_marginTop="15dp"
/>


<Button
android:id="@+id/submitBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#8eb534"
android:textColor="#ffffff"
android:text="@string/submitBtn"
android:layout_marginTop="15dp"
style="?android:attr/borderlessButtonStyle"
/>

</LinearLayout>


</ScrollView>


Secondly i created ForgotPasswordActivity.java

public class ForgotPasswordActivity extends Activity {

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_forgot_password);
}

}


Third I have added some code in manifest file

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

Answer

Presuming you are trying to get the native android action bar and not sherlok one's.....Does your activity extend ActionBarActivity? without that not possibly. After correcting the base class make sure your activity uses a theme that supports action bar.

Comments