Actionbaractivity错误

时间:2015-06-17 16:34:38

标签: android android-actionbar

 public class LoginActivity extends ActionBarActivity {
protected void onCreate(Bundle savedInstanceState) {
    try
    {
    super.onCreate(savedInstanceState);
    System.out.println("here");
    setContentView(R.layout.activity_login);        
        Toolbar mToolBar = (Toolbar)findViewById(R.id.toolbar);
        if(mToolBar != null)
        {
            setSupportActionBar(mToolBar);
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setHomeButtonEnabled(true);
            mToolBar.setNavigationOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //What to do on back clicked
                    finish();
                }
            });         //this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); 
        }
        setTitle("LOGIN");
    }
    catch(Exception e)
    {
        System.out.println(" "+e.getMessage());
    }
}
     

}

      <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white"
    android:minHeight="56dp"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:titleTextAppearance="@style/ToolbarTitle" />
<RelativeLayout
    android:id="@+id/lais"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/toolbar"
    android:orientation="horizontal" >
    <ImageView
        android:id="@+id/image1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:src="@drawable/ic_logo"
        android:padding="10dp" >
    </ImageView>
</RelativeLayout>
<ScrollView
    android:id="@+id/scrollV"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/lais"
    android:fadingEdge="none"
    android:fillViewport="true" >
          <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:layout_margin="20dp"
    android:orientation="vertical" >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:text="Username"
        android:textColor="@android:color/white"
        android:textSize="14sp" />
    <EditText
        android:id="@+id/usernameField"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:drawableLeft="@drawable/bg_username"
        android:drawablePadding="5dp"
        android:inputType="text"
        android:singleLine="true" >
        <requestFocus />
    </EditText>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:text="Password"
        android:textColor="@android:color/white"
        android:textSize="14sp" />
    <EditText
        android:id="@+id/passwordField"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:drawableLeft="@drawable/bg_password"
        android:drawablePadding="5dp"
        android:ems="10"
        android:inputType="textPassword" />
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
        <Button
            android:id="@+id/submitBtn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:layout_marginBottom="10dp"
            android:layout_weight="1"
            android:text="Submit"
            android:textSize="14sp" />        
    </LinearLayout>
</LinearLayout>
</ScrollView>
     

我收到以下错误android.support.v7.internal.widget.ContentFrameLayout无法强制转换为android.support.v7.internal.widget.NativeActionModeAwareLayout。我仍然无法弄清楚错误是什么。

1 个答案:

答案 0 :(得分:0)

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/RelativeLayout12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white"
    android:minHeight="56dp"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:titleTextAppearance="@style/ToolbarTitle" />

尝试上述