Action bar shown in display of android studio but not in my actual app

假装没事ソ 提交于 2019-12-12 03:34:56

问题


Hey guys i have an app with two activities, in the second activity i have an action bar with the title of my app displayed without problem. However in my launcher activity the bar is shown in android studio display but not in the actual app... Any idea whats happening ? Here is my 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>

and here is the xml where the bar is displayed :

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

Im not doing anything concerning the bar in the java files except extending AppCompatActivity in both cases.

Here is the styles file :

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

Thank you for your help.


回答1:


Possibility 1: If your app extends Activity change it to AppCompatActivity.

Possibility 2: Are you sure you don't have different files of different versions named "styles.xml"? Make sure that none of the them have a theme named AppTheme.NoActionBar.

The device you are running the app will fetch the more adequate theme for its version. If you have a file named styles.xml(v21) for example, devices with Lollipop or above will use it.




回答2:


I am thinking that you somehow want to display a listView with content in your activity that has fails to display the action bar. Well here is what I did for mine. In the main method I extended AppCompactActivity and in the method itself I declared the listView as a variable like ListView listView; then after that, in the onCreate method of the main object you just simply connect this to the id of your list using listView = (ListView) findViewById(R.id.thelistid) after that I simply called the adapter that should fill the list with content as listView.setAdapter(nameOfYourAdapter) Hope this helps!



来源:https://stackoverflow.com/questions/36271824/action-bar-shown-in-display-of-android-studio-but-not-in-my-actual-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!