80,354
社区成员
发帖
与我相关
我的任务
分享
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);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="上一步"/>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="标题"
android:textSize="18sp"
android:gravity="center"/>
<Button
android:id="@+id/back1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="下一步"
android:textSize="18sp"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="mystyle" parent="android:Theme.Light">
<item name="android:windowTitleSize">45dp</item>
</style>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ocular.htcvive.uicustomview">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/mystyle">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
它又会报错,是这个You cannot combine custom titles with other title features 你把style.xml文件的theme换成 Theme.AppCompat 的主题就行了,继承AppcompatActivity必须要引用Theme.AppCompat相关的主题样式
你把style.xml文件的theme换成 Theme.AppCompat 的主题就行了,继承AppcompatActivity必须要引用Theme.AppCompat相关的主题样式
继承AppCompatActivity,在布局里添加一个toolbar, 上一步 用 ⬅️ 代替 , 重写onOptionsItemSelected() 中
switch(item.getItemId())
{
case:android.R.id.home:
return true;
}
就可以返回上一步了,
下一步写在一个menu里
重写onCreateOptionsMenu()加载menu布局
继承AppCompatActivity,在布局里添加一个toolbar, 上一步 用 ⬅️ 代替 , 重写onOptionsItemSelected() 中 switch(item.getItemId()) { case:android.R.id.home: return true; } 就可以返回上一步了, 下一步写在一个menu里 重写onCreateOptionsMenu()加载menu布局