API 15 を使用してアクション バーを使用して Android 開発を作成していますが、問題は、アクション バーを画面の上部に表示することです。私の場合、アクションは画面の下にあります誰でも私を助けることができます???
ActionBarTest.java
package com.lebdev.actionbardemo;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class ActionBarTest extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_action_bar_test);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.action_bar_test, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case R.id.iSearch:
search();
return true;
case R.id.iPhoto:
photo();
return true;
case R.id.iVideo:
video();
return true;
default:
}
return super.onOptionsItemSelected(item);
}
private void video() {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), "This is video function", Toast.LENGTH_SHORT).show();
}
private void photo() {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), "This is photo function", Toast.LENGTH_SHORT).show();
}
private void search() {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), "This is search function", Toast.LENGTH_SHORT).show();
}
}
activity_action_bar_test.xml
<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: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=".ActionBarTest" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
文字列.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">ActionBarDemo</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="tsearch">Search</string>
<string name="tphoto">Photo</string>
<string name="tvideo">Video</string>
</resources>
menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>
<item
android:id="@+id/iSearch"
android:orderInCategory="1"
android:showAsAction="ifRoom|withText"
android:title="@string/tsearch">
</item>
<item
android:id="@+id/iPhoto"
android:orderInCategory="2"
android:showAsAction="ifRoom|withText"
android:title="@string/tphoto">
</item>
<item
android:id="@+id/iVideo"
android:orderInCategory="3"
android:showAsAction="ifRoom|withText"
android:title="@string/tvideo">
</item>
</menu>