I'm trying to make a custom action, but it's not working. I followed the instructions of this post almost to the dot, but it's not working. Here's the layout file for my action bar (action_bar_tablet.xml
):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="56dp"
android:background="@drawable/actionbar_background"
android:padding="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="The Commuter"
android:textSize="24sp"
android:textColor="#FFFFFF"/>
<Spinner
android:layout_width="120dp"
android:layout_height="24sp"
android:entries="@string/lines"
android:background="#FFFFFF"
android:clickable="true"
android:layout_marginLeft="80dp"/>
</LinearLayout>
And here's the MainActivity
method that I use to inflate it:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (findViewById(R.id.container) != null) {
TABLET = false;
//...
} else {
if (savedInstanceState == null) {
TABLET = true;
//...
final ViewGroup actionBarLayout = (ViewGroup) getLayoutInflater().inflate(
R.layout.action_bar_tablet,
null);
final ActionBar actionBar = getActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(actionBarLayout);
}
}
}
This seems so simple, but I'm not sure why it's not working. Could someone please help me out?
Thanks in advance :)
Edit 1:
Here's the string.xml
file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">The Commuter Chicago</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="lines">Lines</string>
<string name="stops">Stops</string>
<string name="arrivals">Arrivals</string>
<string-array name="lines">
<item>Red</item>
<item>Blue</item>
<item>Brown</item>
<item>Green</item>
<item>Orange</item>
<item>Purple</item>
<item>Pink</item>
<item>Yellow</item>
</string-array>
</resources>