操作栏显示在Android工作室的显示,但不是在我的实际应用程序中

时间:2016-03-28 21:49:32

标签: android xml android-actionbar

嘿伙计们我有一个有两个活动的应用程序,在第二个活动中我有一个操作栏,我的应用程序的标题显示没有问题。 但是在我的启动器活动中,条形图显示在android studio显示中,但不在实际的应用程序中... 有什么想法吗? 这是我的xml:

  <LinearLayout 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:orientation="vertical"
    tools:context=".Menu_Activity">

<ListView
    android:id="@+id/list"
    android:layout_width="wrap_content"
    android:layout_height="40dp"
    android:layout_weight="0.99"
    android:dividerHeight="2px">

</ListView>

<ProgressBar
    android:id="@+id/progressBar1"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true" />

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Download content"
    android:textColor="#FFFFFF"
    android:id="@+id/button"
    android:background="@drawable/buttonshape" />

 </LinearLayout>

以下是显示栏的xml:

   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">



<ProgressBar
    android:id="@+id/progressBar1"
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"

    />

<ListView
    android:id="@+id/list"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:divider="#FF000080"
    android:dividerHeight="2px">


</ListView>



 </LinearLayout>

除了在两种情况下扩展AppCompatActivity之外,我没有对java文件中的栏做任何事情。

这是样式文件:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>



<style name="AppTheme.AppBarOverlay"     parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

感谢您的帮助。

2 个答案:

答案 0 :(得分:3)

可能性1: 如果您的应用扩展Activity,请将其更改为AppCompatActivity

可能性2: 您确定没有名为“styles.xml”的不同版本的不同文件吗?确保它们都没有名为AppTheme.NoActionBar的主题。

您运行该应用的设备将为其版本获取更适合的主题。例如,如果您有一个名为styles.xml(v21)的文件,那么使用Lollipop或更高版本的设备就会使用它。

答案 1 :(得分:0)

我在想你以某种方式想要在活动中显示一个listView,其中包含无法显示操作栏的内容。那么这就是我为我所做的。在main方法中,我扩展了AppCompactActivity,在方法本身中,我将listView声明为ListView listView;之类的变量,然后在主对象的onCreate方法中,只需使用{将它连接到列表的id即可。 {1}}之后我简单地调用了应该填充列表的适配器,内容为listView = (ListView) findViewById(R.id.thelistid)希望这会有所帮助!