2014-12-07 69 views
0

我可是從0創建一個新的項目,但是當我看到預覽不會顯示任何動作條,我只是從0創建它我沒有任何代碼,Android Studio中RC 4 ActionBar的犯規出現在預覽

一個圖:http://i.stack.imgur.com/CaeE1.png

這裏是我的style.xml:

<resources> 

    <!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
    </style> 

</resources> 

而且我activity_main.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:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity"> 

    <TextView android:text="@string/hello_world" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

</RelativeLayout> 

而且我MainActivity.java:

package com.example.jorwys.myapplication; 

import android.support.v7.app.ActionBarActivity; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuItem; 


public class MainActivity extends ActionBarActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
    } 


    @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_settings) { 
      return true; 
     } 

     return super.onOptionsItemSelected(item); 
    } 
} 

但是當我打開一箇舊的項目預覽確實給我動作條,所以我認爲這個問題是全新的Android工作室;感謝您的幫助。我很抱歉我的英語不好。

回答

0

此預覽僅適用於您的佈局組件。所以如果你想看到你需要將它添加到佈局代碼中的東西。您可以在示例中添加一種查看您並在您的活動中獲取它的訪問權限並根據需要進行更改。

+1

是的但在我更新android studio之前,我可以看到它像這樣https://www.dropbox.com/s/mntyqlkz0ldxcoy/Captura%20de% 20pantalla%202014-12-07%2016.42.11.png?DL = 0 – 2014-12-07 21:13:10

0

我注意到正在編譯API 21(Lollipop),所以我將其更改爲API 19(Kitkat)以及appcompat庫:compile'c​​om.android.support:appcompat-v7:21.0.+'來編譯'com.android.support:appcompat-v7:20+'