无法在同一活动中使用自定义标题栏和浮动操作按钮

时间:2017-06-07 11:55:34

标签: android floating-action-button titlebar

我在将自定义标题栏放入浮动操作按钮活动时遇到问题。有人可以帮助同一活动。 这是我的.xml文件

  <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res                           /android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   tools:context="com.spyn.spyn.ActionBar">

   <android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    app:srcCompat="@android:drawable/ic_dialog_email" />

   </RelativeLayout>

我的自定义标题栏

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="wrap_content">
    <ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@mipmap/ic_arrow_back_black_24dp"

    />
   <LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Dues"
        android:fontFamily="sans-serif"
        android:layout_marginStart="10dp"
        android:textColor="#000000"
        android:textSize="18sp"

        />
      <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="sans-serif"
        android:layout_marginStart="10dp"
        android:textColor="#000000"
        android:id="@+id/clubName"
        android:textSize="11sp"
        />

     </LinearLayout>


    </LinearLayout>

我的活动课

  import android.app.Activity;
  import android.os.Bundle; 
  import android.view.Window;

  public class ActionBar extends Activity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.activity_action_bar);
              getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title_ba r);
    }
   }

错误logcat

17:06:13.996 24826-24826/com.spyn.spyn E/AndroidRuntime: FATAL EXCEPTION: main
                                                               Process: com.spyn.spyn, PID: 24826
                                                               java.lang.RuntimeException: Unable to start activity ComponentInfo{com.spyn.spyn/com.spyn.spyn.ActionBar}: android.view.InflateException: Binary XML file line #9: Error inflating class android.support.design.widget.FloatingActionButton
                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)
                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
                                                                   at android.app.ActivityThread.access$800(ActivityThread.java:151)
                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
                                                                   at android.os.Handler.dispatchMessage(Handler.java:110)
                                                                   at android.os.Looper.loop(Looper.java:193)
                                                                   at android.app.ActivityThread.main(ActivityThread.java:5292)
                                                                   at java.lang.reflect.Method.invokeNative(Native Method)
                                                                   at java.lang.reflect.Method.invoke(Method.java:515)
                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
                                                                   at dalvik.system.NativeStart.main(Native Method)
                                                                Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class android.support.design.widget.FloatingActionButton
                                                                   at android.view.LayoutInflater.createView(LayoutInflater.java:620)
                                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
                                                                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
                                                                   at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:305)
                                                                   at android.app.Activity.setContentView(Activity.java:1944)
                                                                   at com.spyn.spyn.ActionBar.onCreate(ActionBar.java:13)
                                                                   at android.app.Activity.performCreate(Activity.java:5264)
                                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 
                                                                   at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321) 
                                                                   at android.os.Handler.dispatchMessage(Handler.java:110) 
                                                                   at android.os.Looper.loop(Looper.java:193) 
                                                                   at android.app.ActivityThread.main(ActivityThread.java:5292) 
                                                                   at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                   at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) 
                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) 
                                                                   at dalvik.system.NativeStart.main(Native Method) 
                                                                Caused by: java.lang.reflect.InvocationTargetException
                                                                   at java.lang.reflect.Constructor.constructNative(Native Method)
                                                                   at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
                                                                   at android.view.LayoutInflater.createView(LayoutInflater.java:594)
                                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
                                                                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                                                                   at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:305) 
                                                                   at android.app.Activity.setContentView(Activity.java:1944) 
                                                                   at com.spyn.spyn.ActionBar.onCreate(ActionBar.java:13) 
                                                                   at android.app.Activity.performCreate(Activity.java:5264) 
                                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088) 
                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302) 
                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 
                                                                   at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321) 
                                                                   at android.os.Handler.dispatchMessage(Handler.java:110) 
                                                                   at android.os.Looper.loop(Looper.java:193) 
                                                                   at android.app.ActivityThread.main(ActivityThread.java:5292) 
                                                                   at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                   at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) 
                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) 
                                                                   at dalvik.system.NativeStart.main(Native Method) 
                                                                Caused by: java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library.
                                                                   at android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:33)
                                                                   at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:159)
                                                                   at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:153)
                                                                   at java.lang.reflect.Constructor.constructNative(Native Method) 
                                                                   at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
                                                                   at android.view.LayoutInflater.createView(LayoutInflater.java:594) 
                                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
                                                                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                                                                   at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:305) 
                                                                   at android.app.Activity.setContentView(Activity.java:1944) 
                                                                   at com.spyn.spyn.ActionBar.onCreate(ActionBar.java:13) 
                                                                   at android.app.Activity.performCreate(Activity.java:5264) 
                                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088) 
                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302) 
                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 
                                                                   at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321) 
                                                                   at android.os.Handler.dispatchMessage(Handler.java:110) 
                                                                   at android.os.Looper.loop(Looper.java:193) 
                                                                   at android.app.ActivityThread.main(ActivityThread.java:5292) 
                                                                   at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                   at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) 
                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) 
                                                                   at dalvik.system.NativeStart.main(Native Method) 

我已经尝试使用我发现的所有内容,浮动按钮和自定义标题栏的父类都必须扩展。

0 个答案:

没有答案