I use Android 4.2 and minSdkVersion 17 and the application is for tablet.
i can modify the default theme (change only color for my actionbar) with my but not found.
the my manifest is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="example.example.customtheme" >
<application
android:allowBackup="true"
android:icon="#mipmap/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>
</application>
My style.xml is:
<resources>
<style name="AppTheme" parent="#style/Theme.AppCompat">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#A2a</item>
</style>
and MainActivity is:
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#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_main, 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);
}
}
the layout is banal
<RelativeLayout 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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
</RelativeLayout>
The my problem is:
the actionbar is not color (#a2a) but is black
To fix this problem please update your styles.xml as following:
<resources>
<style name="AppTheme" parent="#style/Theme.AppCompat">
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#color/ab_color</item>
<item name="background">#color/ab_color</item>
</style>
</resources>
line <item name="background">#color/ab_color</item> was added and color was moved to colors.xml because aapt could fail to parse it otherwise.
and your colors.xml:
<resources>
<color name="ab_color">#a2a</color>
</resources>
More details about this case: https://developer.android.com/training/basics/actionbar/styling.html
Related
After searching for hours to find the solution for errors in my code, I end up asking a question here.. Ive tried every solutions offered but still couldn't get it right. Maybe there's something wrong in my codes.
So these are my codes:
AboutUsActivity.java:
public class AboutUsActivity extends AppCompatActivity {
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about_us);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}
My AndroidManifest file:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".activity.LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activity.GeneralSettingActivity" android:parentActivityName=".activity.ProfileActivity"/>
<activity android:name=".activity.RegisterActivity" android:parentActivityName=".activity.LoginActivity"/>
<activity android:name=".activity.ResetPasswordActivity" android:parentActivityName=".activity.LoginActivity"/>
<activity android:name=".activity.HomeActivity" />
<activity android:name=".activity.AboutUsActivity"
android:parentActivityName=".activity.HomeActivity"
android:theme="#style/AppTheme.ActionBar"
/>
<activity android:name=".activity.ApplyTutor" android:parentActivityName=".activity.HomeActivity"/>
<activity android:name=".activity.PrivacyPolicyActivity" android:parentActivityName=".activity.HomeActivity"/>
<activity
android:name=".activity.ProfileActivity"
android:label="#string/title_activity_profile"
android:theme="#style/AppTheme.NoActionBar" />
<activity android:name=".activity.EditProfileActivity" android:parentActivityName=".activity.ProfileActivity"/>
<activity android:name=".activity.EarningActivity" android:parentActivityName=".activity.ProfileActivity"/>
<activity android:name=".activity.ScheduleActivity" android:parentActivityName=".activity.ProfileActivity"/>
<activity android:name=".activity.RatingReviewActivity" android:parentActivityName=".activity.ProfileActivity"/>
<activity android:name=".activity.RequestActivity"></activity>
</application>
My styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowFullscreen">false</item>
<item name="windowActionBar">false</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.ActionBar"/>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
my activity_about_us.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.cqaai.tutorpal.activity.AboutUsActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Page name: About Us"/>
</android.support.constraint.ConstraintLayout>
Android Monitor display error:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.app.ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference
at com.example.cqaai.tutorpal.activity.AboutUsActivity.onCreate(AboutUsActivity.java:32)
Edit your Activity to include these two override methods:
public class AboutUsActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about_us);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.about_us_activity, menu);
return true;
}
#Override
public boolean onPrepareOptionsMenu(Menu menu) {
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
}
And make a new Android Resource Directory in your res folder by right clicking the res folder in your project structure and choose Resource Type: menu. Then create a new menu resource file and write the following code in there:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity">
<!-- other possible items -->
</menu>
You are using Theme.AppCompat.Light.NoActionBar as base application theme and that's why getSupportActionBar() returns null. That theme has no action bar as its name suggests. There are two solutions.
First Solution: You can change your theme to a theme with action bar, like Theme.AppCompat.Light.DarkActionBar.
Second Solution: You can continue with Theme.AppCompat.Light.NoActionBar but you have to use Toolbar. For this, you need to update your layout as follows:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.cqaai.tutorpal.activity.AboutUsActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Page name: About Us"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.design.widget.CoordinatorLayout>
...and your AboutUsActivity's onCreate() as follows:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about_us);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
I hope it works now.
i want to make a Login page for the app. however the activity is not showing its only a blank page with a single title bar with a app name that is there. i tried different themes but the problem remains the same.
here is my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="variofitness.com.schedulekeeper">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:allowBackup="true"
android:icon="#mipmap/img_logo"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".HomeActivity"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.NoActionBar">
</activity>
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
And Here is my styles file
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/white</item>
<item name="android:textColorPrimary">#color/lightBlue</item>
<item name="android:windowBackground">#color/white</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="ToolBarStyle" parent="">
<item name="android:background">#android:color/transparent</item>
<item name="titleTextAppearance">?android:textAppearanceLarge</item>
</style>
<style name="ThemeOverlay.MyApp.ActionBar" parent="ThemeOverlay.AppCompat.ActionBar">
<!-- Parent theme sets colorControlNormal to textColorPrimary. -->
<item name="android:textColorPrimary">#color/lightBlue</item>
</style>
</resources>
Here is my java code..
package variofitness.com.schedulekeeper;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.design.widget.TextInputLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
/**
* Created by vinod on 1/29/16.
*/
public class LoginActivity extends AppCompatActivity implements View.OnClickListener{
EditText edtUserName,edt_password;
TextInputLayout input_application_password,input_application_userName;
TextView txt_Forgot_Password;
Button btn_login,btn_request_For_signUp;
#Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
setContentView(R.layout.layout_login);
initializeComponents();
}
private void initializeComponents() {
input_application_password = (TextInputLayout)findViewById(R.id.input_application_password);
input_application_userName = (TextInputLayout)findViewById(R.id.input_application_userName);
edtUserName = (EditText)findViewById(R.id.edtUserName);
edt_password = (EditText)findViewById(R.id.edt_password);
txt_Forgot_Password = (TextView)findViewById(R.id.txt_Forgot_Password);
btn_login = (Button)findViewById(R.id.btn_login);
btn_request_For_signUp = (Button)findViewById(R.id.btn_request_For_signUp);
}
#Override
public void onClick(View view) {
switch (view.getId()){
case R.id.txt_Forgot_Password:
break;
case R.id.btn_login:
break;
case R.id.btn_request_For_signUp:
break;
default:
break;
}
}
}
can anyone help me to tell me what i am missing?
#Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
Replace this piece of code with
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
And you are good to go.
I have made a ListView with selectable items but the ActionMode is not showing properly. (There is and a "compare" menu button on the right with white color)
I tried to style the actionMode with the following code but nothing changes. Any ideas why might this happens? I found out that if I set the background color direct on the Toolbar widget instead of the DarkTheme.ActionBar the color arround the text on actionMode is gone but still the color of the text is white and also I need to have the color of the ActionBar defined on the theme instead of the widget.
toolbar.xml
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/action_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
app:theme="#style/DarkTheme.ActionBar"
app:popupTheme="#style/DarkTheme.Popup"/>
mytheme.xml
<resources>
<style name="DarkTheme.ActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:textColorPrimary">#color/abc_primary_text_material_dark</item>
<item name="actionMenuTextColor">#color/abc_primary_text_material_dark</item>
<item name="android:textColorSecondary">#ffff8800</item>
<item name="android:textAllCaps">false</item>
<item name="android:background">#303030</item>
</style>
<style name="DarkTheme.Popup" parent="ThemeOverlay.AppCompat.Dark">
<item name="android:textColor">#ffffff</item>
</style>
<style name="DarkTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:textColor">#101010</item>
<item name="android:textColorLink">#ff0099cc</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:colorPrimaryDark">#000000</item>
<item name="android:navigationBarColor">#000000</item>
<item name="android:textAllCaps">false</item>
<item name="android:actionModeStyle">#style/DarkTheme.ActionMode</item>
</style>
<style name="DarkTheme.ActionMode" parent="Widget.AppCompat.ActionMode">
<item name="android:actionModeBackground">#android:color/black</item>
<item name="android:background">#000000</item>
<item name="android:backgroundSplit">#000000</item>
</style>
</resources>
I don't realy understand your stuff, it looks strange.
Theme are for Activity or Application in the manifest. For widget you should use style.
When looking at your question, I think, you just don't know how to use theme and what themes are for.
So your theme should looks like a stuff like that:
<resources>
<style name="AppBlankTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="colorPrimary">#color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="colorAccent">#color/accent</item>
</style>
<!--Both themes below are those accepted to make the ToolBar works-->
<!-- Base application theme. -->
<style name="AppTheme" parent="AppBlankTheme">
<!-- Customize your theme here. -->
<!-- Base application theme. -->
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
<style name="MyAppTheme" parent="Theme.AppCompat.NoActionBar"/>
<!--The Theme for the Actvity that have actionMode-->
<style name="ActionModeAppTheme" parent="AppTheme">
<item name="windowActionModeOverlay">true</item>
<item name="actionModeBackground">#color/primary_dark</item>
<item name="actionBarPopupTheme">#style/ThemeOverlay.AppCompat.Light</item>
</style>
</resources>
Then your manifest you looks like something like that:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android2ee.formation.lollipop.toolbar" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".sample.ActivityWithItems"
android:label="#string/title_activity_activity_with_items"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.android2ee.formation.lollipop.toolbar.MainActivity" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.android2ee.formation.lollipop.toolbar.EXAMPLE" />
</intent-filter>
</activity>
<activity
android:name=".sample.ActionModeActivity"
android:label="#string/title_activity_actionmode"
android:theme="#style/ActionModeAppTheme"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.android2ee.formation.lollipop.toolbar.MainActivity" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.android2ee.formation.lollipop.toolbar.EXAMPLE" />
</intent-filter>
</activity>
</application>
</manifest>
And your activity looks like something like that:
public class ActionModeActivity extends AppCompatActivity {
ActionMode mMode;
/**
* The action Bar
*/
private ActionBar actionBar;
private Toolbar toolbar;
Callback actionModeCallBack;
private boolean postICS,postLollipop;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//You could also hide the action Bar
// getSupportActionBar().hide();
setContentView(R.layout.activity_action_mode);
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setNavigationIcon(R.drawable.ic_action_custom_up);
postICS =getResources().getBoolean(R.bool.postICS);
postLollipop =getResources().getBoolean(R.bool.postLollipop);
if(postLollipop){
toolbar.setElevation(15);
}
setSupportActionBar(toolbar);
actionBar=getSupportActionBar();
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
// Show the Up button in the action bar.
findViewById(R.id.start_actionmode).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
enableActionMode();
}
});
findViewById(R.id.stop_actionmode).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (mMode != null) {
//To quit the ActionMode
mMode.finish();
}
}
});
actionModeCallBack=new Callback() {
#Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
#Override
public void onDestroyActionMode(ActionMode mode) {
}
#Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
getMenuInflater().inflate(R.menu.action_mode, menu);
return true;
}
#Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
Toast.makeText(ActionModeActivity.this, "Got click: " + item, Toast.LENGTH_SHORT).show();
mode.finish();
return true;
}
};
}
private void enableActionMode() {
mMode = startSupportActionMode(actionModeCallBack);
}
#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_activity_with_items, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. Use NavUtils to allow users
// to navigate up one level in the application structure. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
//
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
}
I am following the Android Developers Guild
I want to have the green robot logo on the very left hand side of the action bar
http://developer.android.com/images/training/basics/actionbar-theme-custom#2x.png
but I do not have the logo on action bar at all. I have searched for a few days, still can not locate an answer for this.
Please help, thanks!
src/.../MainActivity.java
public class MainActivity extends ActionBarActivity {
public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setDisplayUseLogoEnabled(true);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.action_bar, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.action_tab:
ActionBar.openTab(this);
return true;
case R.id.action_search:
ActionBar.openSearch(this);
return true;
case R.id.action_settings:
ActionBar.openSettings(this);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
/** Called when the user clicks the Send button */
public void sendMessage(View view) {
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}
menu/action_bar.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!-- Tab, should appear as action button -->
<item android:id="#+id/action_tab"
android:title="#string/action_tab"
app:showAsAction="always" /> <!-- you can change "always" to "ifRoom" -->
<!-- Search, should appear as action button -->
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
app:showAsAction="always" /> <!-- you can change "always" to "ifRoom|withText" -->
<!-- Settings, should always be in the overflow -->
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
app:showAsAction="never" />
</menu>
res/values/themes.xml
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionMenuTextColor">#color/actionbar_otherthantitleandoverflowtext</item>
<item name="android:windowActionBarOverlay">false</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionMenuTextColor">#color/actionbar_otherthantitleandoverflowtext</item>
<item name="windowActionBarOverlay">false</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#color/actionbar_background</item>
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
<!-- Support library compatibility -->
<item name="background">#color/actionbar_background</item>
<item name="titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText"
parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/actionbar_titletext</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>
</resources>
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:logo="#drawable/ic_launcher"
android:theme="#style/CustomActionBarTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName=".MainActivity" >
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>
</application>
</manifest>
I have my values-v11/styles.xml file as follows, but the ActionBar won't show on my Nexus 5 (API 19). It manages to style the TextView and background, so the Theme is being set, just not with the ActionBar. What's going wrong?
styles.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Base application theme. -->
<style name="AppTheme" parent="#style/Theme.AppCompat">
<item name="android:textViewStyle">#style/AppTheme.TextView</item>
<item name="android:actionBarStyle">#style/ActionBar</item>
</style>
<style name="ActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/ab_solid</item>
</style>
<style name="AppTheme.TextView" parent="android:Widget.TextView" >
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:padding">10dp</item>
<item name="android:gravity">center</item>
<item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
</style>
<style name="AppTheme.TextView.Header">
<item name="android:textColor">#666666</item>
</style>
</resources>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uk.lobsterdoodle.kkworkhours.app" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="uk.lobsterdoodle.kkworkhours.app.WeekActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
package uk.lobsterdoodle.kkworkhours.app;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TableRow;
public class WeekActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_schedule);
...some non-actionbar related stuff...
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.week, 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);
}
}