简体   繁体   中英

Android, ActionBar hiding other widgets

Disclaimer: It's build with CLI only tools, so certainly some "auto-generated lines" are missing

It's a small application with a MainActivity with a EditText and a Button

It works fine, but if I extends now from ActionBarActivity now my EditText and Button are hidden behind the Action Bar

https://developer.android.com/guide/topics/ui/actionbar.html The android documentation does not state about changes needing to be made in the layout.xml nor does the Training guide from which my application is based on

My MainActivity.java

public class MainActivity extends ActionBarActivity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // adding these lines show that the widget are correctly added
        //ActionBar actionBar = getSupportActionBar();
        //actionBar.hide();
    }
}

My main layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
>
    <EditText
        android:id="@+id/enter_verb"
        android:hint="@string/enter_verb"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
    />
    <Button
        android:text="@string/button_conjugate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
    />
</LinearLayout>

My guess would be that I need to add something in my layout to make it aware there's a Action Bar, but I can't find anywhere what it should be.

Very strange, I've added the line coming from this link https://developer.android.com/training/basics/actionbar/overlaying.html

Which is:

android:paddingTop="?attr/actionBarSize"

in my LinearLayout tag, and then recompiled, after that the widget were shown but with a padding of the size of the actionBar in addition to the actionBar itself.

I then removed the line, recompiled and it now works as expected

A bug because of temporary files?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM