Reputation: 144
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>
Upvotes: 0
Views: 2431
Reputation: 7215
In my second Activity, I had to handle the onCreateOptionsMenu()
handler again:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.topmenu, menu);
return true;
}
and also the menu items' event handlers too:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.menu_home:
gotohome();
return true;
case R.id.menu_admin:
gotoadmin();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
UPDATE: I decided to create a base activity class that all my activities will inherit from. I put all the shared code in there.
Upvotes: 1
Reputation: 8633
I had faced the similar problem. My class was extending 'Activity' and not 'ActionBarActivity'. The Action Bar showed up after I extended the 'ActionBarActivity'.
Upvotes: 0
Reputation: 1902
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.
Upvotes: 3