2016-05-08 123 views
0

我已經創建了谷歌地圖,操作欄和菜單沒有顯示我嘗試了不同的解決方案,但沒有主題已經解決了這個問題操作欄和菜單上沒有顯示的片段活動

public class FitnessTrackerActivity extends FragmentActivity { 
    private GoogleMap map; 
    GpsTracker gps; 
    TrackDBHelper mDBHelper; 
    // Fields for flash functionality 
    Camera camera; 
    Camera.Parameters parameters; 

    String date; 
    TextView transportation; 
    TextView distance; 
    TextView calories; 
    Chronometer chrono; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_fitness_tracker); 



     Time today = new Time(Time.getCurrentTimezone()); 
     today.setToNow(); 
     date = today.format("%k:%M:%S"); 
     if (isFlashSupported()) { 
      camera = Camera.open(); 
      parameters = camera.getParameters(); 
     } else { 
      showNoFlashAlert(); 
     } 

    } 
    @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_fitness_tracker, 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. 
     switch (item.getItemId()) { 
      case R.id.led_on: 
       // Turn on LED 
       parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); 
       camera.setParameters(parameters); 
       camera.startPreview(); 
       return true; 
      case R.id.led_off: 
       // Turn off LED 
       parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF); 
       camera.setParameters(parameters); 
       camera.stopPreview(); 
       return true; 
      default: 
       return super.onOptionsItemSelected(item); 
     } 
    } 

    private void showNoFlashAlert() { 
     new AlertDialog.Builder(this) 
       .setMessage("Your device hardware does not support flashlight!") 
.setIcon(android.R.drawable.ic_dialog_alert).setTitle("Error") 
       .setPositiveButton("Ok", new DialogInterface.OnClickListener() { 

        @Override 
        public void onClick(DialogInterface dialog, int which) { 
         dialog.dismiss(); 
         finish(); 
        } 
       }).show(); 
    } 

    private boolean isFlashSupported() { 
     PackageManager pm = getPackageManager(); 
     return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH); 
    } 
} 
片段活動

,這是我試圖使用菜單:

<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=".FitnessTrackerActivity"> 
    <item android:id="@+id/led_on" 
     android:title="LED On" 
     app:showAsAction="withText"/> 
    <item android:id="@+id/led_off" 
     android:title="LED Off" 
     app:showAsAction="withText"/> 
</menu> 

這是FitnessTrackerActivity XML

<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=".FitnessTrackerActivity" 
    tools:showIn="@layout/activity_fitness_tracker"> 
    <fragment 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/map" 
     android:name="com.google.android.gms.maps.MapFragment" 
     android:layout_marginBottom="150dp" 
     /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/btnStartStop" 
     android:onClick="onButtonStartStopClick" 
     android:layout_alignParentBottom="true" 
     android:id="@+id/btnStartStop" 
     android:layout_marginBottom="40dp" 
     android:layout_marginLeft="20dp" 
     /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/caloriesVal" 
     android:text="0" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:layout_marginBottom="40dp" 
     android:layout_marginRight="20dp" 
     android:textSize="20sp"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/caloriesText" 
     android:text="@string/caloriesText" 
     android:layout_alignParentBottom="true" 
     android:layout_toLeftOf="@+id/caloriesVal" 
     android:layout_marginBottom="40dp" 
     android:layout_marginRight="5dp" 
     android:textSize="20sp"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/timerText" 
     android:text="@string/timer" 
     android:layout_above="@id/caloriesText" 
     android:layout_toLeftOf="@+id/timerVal" 
     android:layout_marginRight="5dp" 
     android:textSize="20sp"/> 

    <Chronometer 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/timerVal" 
     android:layout_above="@id/caloriesText" 
     android:layout_alignParentRight="true" 
     android:layout_marginRight="20dp" 
     android:textSize="20sp"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/distanceVal" 
     android:text="0" 
     android:layout_above="@id/timerText" 
     android:layout_alignParentRight="true" 
     android:layout_marginRight="20dp" 
     android:textSize="20sp"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/distanceText" 
     android:text="@string/distanceText" 
     android:layout_above="@id/timerText" 
     android:layout_toLeftOf="@id/distanceVal" 
     android:layout_marginRight="5dp" 
     android:textSize="20sp"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/transportationSel" 
     android:layout_above="@id/distanceText" 
     android:layout_alignParentRight="true" 
     android:layout_marginRight="20dp" 
     android:textSize="20sp"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/transportationText" 
     android:text="@string/transportationText" 
     android:layout_above="@id/distanceText" 
     android:layout_toLeftOf="@id/transportationSel" 
     android:layout_marginRight="5dp" 
     android:textSize="20sp"/> 
</RelativeLayout> 
+0

activity_fitness_tracker.xml請。 – Amir

回答

0

ActionBar使用AppCompatActivity,但你可以把谷歌地圖放在片段中,使用setChildFragmentMenger並將你的layoutFragment放到AppCompatActivity佈局中,並在AppCompatActivity的ActionBar中,希望它的幫助

相關問題