小弟按照网上的说法写的代码,但是总是报错:
You cannot combine custom titles with other title features
网上说这个错误是给标题栏指定了两个title,但是我没有啊。。。。还请指教啊,下面是代码:
ChangeTitleActivity.java
- Java code
package Rinder.ChangeTitle;import android.app.Activity;import android.os.Bundle;import android.view.Window;import android.view.WindowManager;public class ChangeTitleActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);// 左侧图标显示,可以实现// requestWindowFeature(Window.FEATURE_LEFT_ICON);// setContentView(R.layout.main);// getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.ic_launcher); //全屏显示,不显示标题栏可以实现// requestWindowFeature(Window.FEATURE_NO_TITLE);// setContentView(R.layout.main);// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //就是下面这句话会使用自己的title回出错 requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.main); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title); }}
一般说是在manifest里设置了Activity的theme属性可能造成这个问题。。。。。。
AndroidManifest.xml代码
- XML code
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="Rinder.ChangeTitle" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="14" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name"> <activity android:name=".ChangeTitleActivity" android:label="@string/app_name"> <intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>
其实应该是requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);这句就错了,但是还是把自定义的title贴出来
自定义的title.xml
- XML code
<?xml version="1.0" encoding="UTF-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" android:gravity="bottom"/> <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:text="文本" /> </LinearLayout>
我想难道是我自己指定的title和他默认的冲突了?、但是requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);就是告诉系统我要使用自定义的啊??请大侠指教~~~~
------解决方案--------------------
你这是 4.0吗 可能是布局文件的问题吗?
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"