我使用操作欄,但由於某些原因,圖標顯示不出來圖標在動作條沒有顯示
這裏是我的活動XML代碼
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.menz.projectv4.MainActivity"
tools:showIn="@layout/activity_main">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/LVTimetable"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:choiceMode="none" />
</RelativeLayout>
這裏是菜單XML
<menu 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"
tools:context="com.example.menz.projectv4.MainActivity">
<item android:id="@+id/action_addReminder"
android:title="Add Reminder"
android:icon="@drawable/add"
app:showAsAction="ifRoom"/>
<item android:id="@+id/action_search"
android:title="Search"
android:icon="@drawable/search"
app:showAsAction="ifRoom"/>
</menu>
和Mainfest文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.menz.projectv4">
<application
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.DeviceDefault.Light.DarkActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".add" />
<activity android:name=".display" />
<activity android:name=".search"></activity>
</application>
</manifest>
我已經嘗試了一些張貼其他的解決方案,像
android:showAsAction ="always"
它仍然沒有工作然後我試圖改變應用程序還是同樣的事情的主題
在此先感謝
這裏是活動Java文件
package com.example.menz.projectv4;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CursorAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.SimpleCursorAdapter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
public class MainActivity extends Activity implements ListView.OnItemClickListener{
static String row_id = "row_id";
private ListView Timetable ;
private CursorAdapter cursorAdapter;
private DatabaseConnector databaseConnector;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_main);
Timetable = (ListView)findViewById(R.id.LVTimetable);
Timetable.setOnItemClickListener(this);
String [] from = new String [] {"Subject","Assignment"};
int [] to = new int [] {R.id.TVTitle,R.id.TVSubject};
cursorAdapter = new SimpleCursorAdapter(MainActivity.this,R.layout.list_view_layout,null,from,to);
Timetable.setAdapter(cursorAdapter);
}
@Override
protected void onResume() {
super.onResume();
new GetAllTask().execute((Object[]) null);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent viewTask = new Intent(this,display.class);
viewTask.putExtra(row_id,id);
startActivity(viewTask);
}
private class GetAllTask extends AsyncTask<Object , Object , Cursor>
{
DatabaseConnector databaseConnector = new DatabaseConnector(MainActivity.this);
@Override
protected Cursor doInBackground(Object... params) {
try {
databaseConnector.open();
} catch (SQLException e) {
e.printStackTrace();
}
return databaseConnector.getAllTasks();
}
@Override
protected void onPostExecute(Cursor result) {
cursorAdapter.changeCursor(result);
databaseConnector.close();
}
}
@Override
protected void onPause() {
super.onPause();
}
@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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_addReminder) {
startActivity(new Intent(this,add.class));
}
return super.onOptionsItemSelected(item);
}
下面是活動
點擊菜單,然後嘗試 –
向我們提供您的Java代碼!也許你沒有在那裏設置什麼? – RexSplode
你實現onCreateOptionsMenu在您的活動類文件發表您的活動Java類 – Pavan