android 继承自定义activity,关于已继承兼容包的Activity怎么自定义标题栏

如下面代码所示,是活动直接继承Activity时自定义标题栏的代码

MainActivity

package com.ocular.htcvive.uicustomview;

import android.app.Activity;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.Window;

public class MainActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

setContentView(R.layout.activity_main);

getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.titlebar);

}

}

titlebar.xml

android:orientation="horizontal" android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/back"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="上一步"/>

android:layout_width="0dp"

android:layout_weight="1"

android:layout_height="wrap_content"

android:text="标题"

android:textSize="18sp"

android:gravity="center"/>

android:id="@+id/back1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="下一步"

android:textSize="18sp"/>

自定义的主题

45dp

AndroidManifest.xml

package="com.ocular.htcvive.uicustomview">

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:supportsRtl="true"

android:theme="@style/mystyle">

实现的结果如下

ece0d22e80c27f593aee3d78575298fe.png

问:假如活动Activity是继承兼容包的话,该怎么实现上面那种效果。原因是本人把Activity改成AppcompatActivity时,就会报出如下错误

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ocular.htcvive.uicustomview/com.ocular.htcvive.uicustomview.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值