2016-05-08 11 views
0

ich ein Fragment Aktivität für Google-Karte erstellt haben, aber die Aktionsleiste und Menü zeigen nicht, dass ich andere Lösung aber keines Thema versucht hat, das ProblemAktionsleiste und Menü zeigen nicht auf dem Fragment Aktivität

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); 
    } 
} 
gelöst

und das ist das Menü, das ich zu verwenden ist versucht:

<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> 

ist dies die 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 bitte. – Amir

Antwort

0

ActionBar Arbeit mit AppCompatActivity, aber können Sie das googleMap in Fragmente setzen, mit setChildFragmentMenger und Ihren layoutFragment im AppCompatActivity Layout setzen und die ActionBar in AppCompatActivity, hoffen seine Hilfe

Verwandte Themen