我正在使用API 15創建具有動作欄的android開發,但問題是我想讓動作欄位於屏幕的頂部。在我的情況下,行動是在任何人都可以幫助我的屏幕下?android開發如何創建動作欄
ActionBarTest.javapackage 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>
String.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>
http://developer.android.com/training/basics/actionbar/adding-buttons.html這裏閱讀 – 2013-10-01 07:22:30
這是一個糟糕的設計,Android不建議底部的Action bar。 –
@Brontok這就是爲什麼他希望頂部的操作欄。 – Lennart