【问题标题】:Android Studio RC 4 ActionBar doesnt appear in previewAndroid Studio RC 4 ActionBar 未出现在预览中
【发布时间】:2015-02-05 11:59:46
【问题描述】:

我从 0 创建一个新项目,但是当我看到预览没有显示任何 actionBar 时,我只是从 0 创建它,我没有任何代码,

一张图片: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 studio 上;感谢您的帮助。我很抱歉我的英语不好。

【问题讨论】:

    标签: android android-actionbar styles preview android-appcompat


    【解决方案1】:

    此预览仅适用于您的布局组件。因此,如果您想在那里看到一些东西,您必须将其添加到您的布局代码中。例如,您可以添加一种 View you 并在您的 Activity 中获取它并根据需要进行更改。

    【讨论】:

    【解决方案2】:

    我注意到它正在使用 API 21 (Lollipop) 进行编译,所以我将其更改为 API 19 (Kitkat) 以及 appcompat 库: compile 'com.android.support:appcompat-v7:21.0.+' to compile ' com.android.support:appcompat-v7:20+'

    【讨论】:

      猜你喜欢
      • 2021-01-05
      • 2015-03-31
      • 1970-01-01
      • 1970-01-01
      • 2021-09-15
      • 2018-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多