你好我的code得到错误。你能告诉我怎么解决这个问题。
样式code
<样式名称=AppTheme父=AppTheme.Base/>
<样式名称=AppTheme.Base父=Theme.AppCompat.Light>
活动code
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
//设置有按键的自定义标题
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
的setContentView(R.layout.create_account_screen_1);
getWindow()。setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.title_layout_with_two_button);
((TextView中)findViewById(R.id.myTitle))的setText(R.string.create_acc)。
//((按钮)findViewById(R.id.back_button))的setText(R.string.login)。
((按钮)findViewById(R.id.right_button))setVisibility(View.INVISIBLE)。
清单code
<活动机器人:名称=。CreateAccountActivity1
机器人:主题=@风格/ AppTheme/>
** create_account_screen_1 **
< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:后台=#fafafa
机器人:方向=垂直>
<查看
机器人:layout_width =match_parent
机器人:layout_height =0.5dp
机器人:背景=@机器人:彩色/黑白/>
<的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:重力=右
机器人:方向=垂直
机器人:paddingRight =5DP
机器人:paddingTop =3DP
机器人:ID =@ + ID / scrollview_bottom>
<的TextView
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginRight =5SP
机器人:TEXTSIZE =@扪/ DEFAULT_SIZE
机器人:文字颜色=@彩色/黑白
机器人:textAppearance =机器人:ATTR / textAppearanceMedium
机器人:文本=@字符串/ step_1_2
机器人:能见度=水涨船高/>
<的TextView
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginRight =5SP
机器人:layout_marginTop =10SP
机器人:TEXTSIZE =@扪/ DEFAULT_SIZE
机器人:文字颜色=@彩色/黑白
机器人:textAppearance =机器人:ATTR / textAppearanceMedium
机器人:可点击=真
机器人:的onClick =whatsThisClick
机器人:文本=@字符串/ what_this
机器人:能见度=水涨船高/>
<的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直>
<滚动型
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT>
<的LinearLayout
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =280sp
机器人:paddingTop =5SP
机器人:重力=center_horizontal
机器人:layout_gravity =center_horizontal
机器人:方向=垂直>
<的TextView
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =FILL_PARENT
机器人:文本=@字符串/用户名
机器人:TEXTSIZE =@扪/ DEFAULT_SIZE
机器人:文字颜色=@彩色/黑白
机器人:textAppearance =机器人:ATTR / textAppearanceMedium
机器人:layout_marginTop =5DP/>
<的EditText
机器人:ID =@ + ID /用户名
机器人:layout_width =FILL_PARENT
机器人:TEXTSIZE =@扪/ DEFAULT_SIZE
机器人:单线=真
机器人:inputType =textEmailAddress
机器人:layout_marginTop =4DP
机器人:layout_height =40dp
机器人:背景=@可绘制/ rouned_corner
机器人:以下属性来=5DP>
<不是requestFocus />
< /的EditText>
<的TextView
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =FILL_PARENT
机器人:文本=@字符串/ DOB
机器人:TEXTSIZE =@扪/ DEFAULT_SIZE
机器人:文字颜色=@彩色/黑白
机器人:textAppearance =机器人:ATTR / textAppearanceMedium
机器人:layout_marginTop =5DP/>
<的EditText
机器人:ID =@ + ID / dobText
机器人:layout_width =FILL_PARENT
机器人:TEXTSIZE =@扪/ DEFAULT_SIZE
机器人:单线=真
机器人:inputType =日期
机器人:提示=@字符串/ dateMMDDYYYY
机器人:最大长度=10
机器人:可点击=假
机器人:可聚焦=真
机器人:layout_marginTop =4DP
机器人:layout_height =40dp
机器人:背景=@可绘制/ rouned_corner
机器人:以下属性来=5DP> < - 机器人:的onClick =onDobTextClick - >
< /的EditText>
<的TextView
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =FILL_PARENT
机器人:文本=@字符串/密码
机器人:TEXTSIZE =@扪/ DEFAULT_SIZE
机器人:文字颜色=@彩色/黑白
机器人:textAppearance =机器人:ATTR / textAppearanceMedium
机器人:layout_marginTop =5DP/>
<的EditText
机器人:ID =@ + ID /密码
机器人:layout_width =FILL_PARENT
机器人:TEXTSIZE =@扪/ DEFAULT_SIZE
机器人:单线=真
机器人:inputType =数字
机器人:最大长度=4
机器人:layout_marginTop =4DP
机器人:layout_height =40dp
机器人:背景=@可绘制/ rouned_corner
机器人:以下属性来=5DP>
< /的EditText>
<的TextView
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =FILL_PARENT
机器人:文本=@字符串/ conform_password
机器人:TEXTSIZE =@扪/ DEFAULT_SIZE
机器人:文字颜色=@彩色/黑白
机器人:textAppearance =机器人:ATTR / textAppearanceMedium
机器人:layout_marginTop =5DP/>
<的EditText
机器人:ID =@ + ID / conform_password
机器人:layout_width =FILL_PARENT
机器人:TEXTSIZE =@扪/ DEFAULT_SIZE
机器人:单线=真
机器人:inputType =数字
机器人:最大长度=5
机器人:layout_marginTop =4DP
机器人:layout_height =40dp
机器人:背景=@可绘制/ rouned_corner
机器人:以下属性来=5DP
机器人:layout_marginBottom =20dp>
< /的EditText>
< / LinearLayout中>
< /滚动型>
< / LinearLayout中>
< / LinearLayout中>
<的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:后台=#fafafa
机器人:方向=垂直
机器人:重力=底
>
<查看
机器人:layout_width =match_parent
机器人:layout_height =0.5dp
机器人:背景=@机器人:彩色/黑白/>
<的LinearLayout
机器人:后台=#fafafa
机器人:layout_width =match_parent
机器人:layout_height =60dp
机器人:方向=横向
机器人:重力=中心
机器人:能见度=有形与GT;
<按钮
机器人:ID =@ + ID / submitBtn
机器人:layout_width =100dp
机器人:layout_height =40dp
机器人:背景=@可绘制/ button_bg
机器人:的onClick =下一步
机器人:文本=@字符串/下一个
机器人:文字颜色=@色/白
机器人:TEXTSIZE =@扪/ DEFAULT_SIZE
机器人:TEXTSTYLE =黑体/>
< / LinearLayout中>
< / LinearLayout中>
< / LinearLayout中>
以上code是我的布局文件。
登录猫误差
12-09 23:42:21.750:E / AndroidRuntime(10108):致命异常:主要
12-09 23:42:21.750:E / AndroidRuntime(10108):java.lang.RuntimeException的:无法启动的活动ComponentInfo {com.velantech.activity / com.velantech.activity.ForgotUserIDActivity}:android.util.AndroidRuntimeException:你不能将自定义标题与其他标题功能
12-09 23:42:21.750:E / AndroidRuntime(10108):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
12-09 23:42:21.750:E / AndroidRuntime(10108):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
12-09 23:42:21.750:E / AndroidRuntime(10108):在android.app.ActivityThread.access $ 600(ActivityThread.java:130)
12-09 23:42:21.750:E / AndroidRuntime(10108):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1195)
12-09 23:42:21.750:E / AndroidRuntime(10108):在android.os.Handler.dispatchMessage(Handler.java:99)
12-09 23:42:21.750:E / AndroidRuntime(10108):在android.os.Looper.loop(Looper.java:137)
12-09 23:42:21.750:E / AndroidRuntime(10108):在android.app.ActivityThread.main(ActivityThread.java:4745)
12-09 23:42:21.750:E / AndroidRuntime(10108):在java.lang.reflect.Method.invokeNative(本机方法)
12-09 23:42:21.750:E / AndroidRuntime(10108):在java.lang.reflect.Method.invoke(Method.java:511)
12-09 23:42:21.750:E / AndroidRuntime(10108):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:786)
12-09 23:42:21.750:E / AndroidRuntime(10108):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-09 23:42:21.750:E / AndroidRuntime(10108):在dalvik.system.NativeStart.main(本机方法)
12-09 23:42:21.750:E / AndroidRuntime(10108):由:android.util.AndroidRuntimeException:不能将自定义标题与其他标题功能
12-09 23:42:21.750:E / AndroidRuntime(10108):在com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:227)
12-09 23:42:21.750:E / AndroidRuntime(10108):在com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2601)
12-09 23:42:21.750:E / AndroidRuntime(10108):在com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2844)
12-09 23:42:21.750:E / AndroidRuntime(10108):在com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:252)
12-09 23:42:21.750:E / AndroidRuntime(10108):在android.app.Activity.setContentView(Activity.java:1867)
12-09 23:42:21.750:E / AndroidRuntime(10108):在com.velantech.activity.ForgotUserIDActivity.onCreate(ForgotUserIDActivity.java:54)
12-09 23:42:21.750:E / AndroidRuntime(10108):在android.app.Activity.performCreate(Activity.java:5008)
12-09 23:42:21.750:E / AndroidRuntime(10108):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
12-09 23:42:21.750:E / AndroidRuntime(10108):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
12-09 23:42:21.750:E / AndroidRuntime(10108):11 ...更多
解决方案
您使用的主题 Theme.AppCompat.Light
包含这一定义(其父):
<项目名称=机器人:windowNoTitle>真< /项目>
因此主题说,它没有标题和你tyring使用自定义标题。这是不兼容的。
您正在使用的主题包含一个操作栏,并在操作栏标题的处理方式不同。请参见风格化的操作栏。
编辑:建议轻的主题没有行动起来吧
要获得一个光的主题没有行动起来吧(这样你就可以使用自定义标题),这应该工作:
<样式名称=AppTheme父=Theme.AppCompat.Light>
<项目名称=windowActionBar>假< /项目>
<项目名称=机器人:windowNoTitle>假< /项目>
< /风格>
Hi in my code getting error. Can you tell me how to fix the issue.
Style Code
<style name="AppTheme" parent="AppTheme.Base"/>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light">
Activity code
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// To set the custom title with Button
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.create_account_screen_1);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.title_layout_with_two_button);
((TextView) findViewById(R.id.myTitle)).setText(R.string.create_acc);
// ((Button) findViewById(R.id.back_button)).setText(R.string.login);
((Button) findViewById(R.id.right_button)).setVisibility(View.INVISIBLE);
Manifest code
<activity android:name=".CreateAccountActivity1"
android:theme="@style/AppTheme"/>
** create_account_screen_1**
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fafafa"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@android:color/black" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="vertical"
android:paddingRight="5dp"
android:paddingTop="3dp"
android:id="@+id/scrollview_bottom">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5sp"
android:textSize="@dimen/default_size"
android:textColor="@color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/step_1_2"
android:visibility="gone" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5sp"
android:layout_marginTop="10sp"
android:textSize="@dimen/default_size"
android:textColor="@color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:clickable="true"
android:onClick="whatsThisClick"
android:text="@string/what_this"
android:visibility="gone" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="280sp"
android:paddingTop="5sp"
android:gravity="center_horizontal"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="@string/user_name"
android:textSize="@dimen/default_size"
android:textColor="@color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginTop="5dp"/>
<EditText
android:id="@+id/user_name"
android:layout_width="fill_parent"
android:textSize="@dimen/default_size"
android:singleLine="true"
android:inputType="textEmailAddress"
android:layout_marginTop="4dp"
android:layout_height="40dp"
android:background="@drawable/rouned_corner"
android:paddingLeft="5dp" >
<requestFocus />
</EditText>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="@string/dob"
android:textSize="@dimen/default_size"
android:textColor="@color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginTop="5dp" />
<EditText
android:id="@+id/dobText"
android:layout_width="fill_parent"
android:textSize="@dimen/default_size"
android:singleLine="true"
android:inputType="date"
android:hint="@string/dateMMDDYYYY"
android:maxLength="10"
android:clickable="false"
android:focusable="true"
android:layout_marginTop="4dp"
android:layout_height="40dp"
android:background="@drawable/rouned_corner"
android:paddingLeft="5dp" > <!-- android:onClick="onDobTextClick" -->
</EditText>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="@string/password"
android:textSize="@dimen/default_size"
android:textColor="@color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginTop="5dp" />
<EditText
android:id="@+id/password"
android:layout_width="fill_parent"
android:textSize="@dimen/default_size"
android:singleLine="true"
android:inputType="number"
android:maxLength="4"
android:layout_marginTop="4dp"
android:layout_height="40dp"
android:background="@drawable/rouned_corner"
android:paddingLeft="5dp" >
</EditText>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="@string/conform_password"
android:textSize="@dimen/default_size"
android:textColor="@color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginTop="5dp" />
<EditText
android:id="@+id/conform_password"
android:layout_width="fill_parent"
android:textSize="@dimen/default_size"
android:singleLine="true"
android:inputType="number"
android:maxLength="5"
android:layout_marginTop="4dp"
android:layout_height="40dp"
android:background="@drawable/rouned_corner"
android:paddingLeft="5dp"
android:layout_marginBottom="20dp" >
</EditText>
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fafafa"
android:orientation="vertical"
android:gravity="bottom"
>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@android:color/black" />
<LinearLayout
android:background="#fafafa"
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal"
android:gravity="center"
android:visibility="visible" >
<Button
android:id="@+id/submitBtn"
android:layout_width="100dp"
android:layout_height="40dp"
android:background="@drawable/button_bg"
android:onClick="next"
android:text="@string/next"
android:textColor="@color/white"
android:textSize="@dimen/default_size"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
the above code is my layout file.
log-cat error
12-09 23:42:21.750: E/AndroidRuntime(10108): FATAL EXCEPTION: main
12-09 23:42:21.750: E/AndroidRuntime(10108): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.velantech.activity/com.velantech.activity.ForgotUserIDActivity}: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
12-09 23:42:21.750: E/AndroidRuntime(10108): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
12-09 23:42:21.750: E/AndroidRuntime(10108): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
12-09 23:42:21.750: E/AndroidRuntime(10108): at android.app.ActivityThread.access$600(ActivityThread.java:130)
12-09 23:42:21.750: E/AndroidRuntime(10108): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
12-09 23:42:21.750: E/AndroidRuntime(10108): at android.os.Handler.dispatchMessage(Handler.java:99)
12-09 23:42:21.750: E/AndroidRuntime(10108): at android.os.Looper.loop(Looper.java:137)
12-09 23:42:21.750: E/AndroidRuntime(10108): at android.app.ActivityThread.main(ActivityThread.java:4745)
12-09 23:42:21.750: E/AndroidRuntime(10108): at java.lang.reflect.Method.invokeNative(Native Method)
12-09 23:42:21.750: E/AndroidRuntime(10108): at java.lang.reflect.Method.invoke(Method.java:511)
12-09 23:42:21.750: E/AndroidRuntime(10108): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-09 23:42:21.750: E/AndroidRuntime(10108): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-09 23:42:21.750: E/AndroidRuntime(10108): at dalvik.system.NativeStart.main(Native Method)
12-09 23:42:21.750: E/AndroidRuntime(10108): Caused by: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
12-09 23:42:21.750: E/AndroidRuntime(10108): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:227)
12-09 23:42:21.750: E/AndroidRuntime(10108): at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2601)
12-09 23:42:21.750: E/AndroidRuntime(10108): at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2844)
12-09 23:42:21.750: E/AndroidRuntime(10108): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:252)
12-09 23:42:21.750: E/AndroidRuntime(10108): at android.app.Activity.setContentView(Activity.java:1867)
12-09 23:42:21.750: E/AndroidRuntime(10108): at com.velantech.activity.ForgotUserIDActivity.onCreate(ForgotUserIDActivity.java:54)
12-09 23:42:21.750: E/AndroidRuntime(10108): at android.app.Activity.performCreate(Activity.java:5008)
12-09 23:42:21.750: E/AndroidRuntime(10108): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
12-09 23:42:21.750: E/AndroidRuntime(10108): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
12-09 23:42:21.750: E/AndroidRuntime(10108): ... 11 more
解决方案
The theme you are using Theme.AppCompat.Light
contains this definition (in its parent):
<item name="android:windowNoTitle">true</item>
So the theme says that it has no title and you are tyring to use a custom title. This is incompatible.
The theme you are using contains an action bar, and the title in the action bar is handled differently. See Styling the Action Bar.
EDIT: Suggestion for light theme without action bar
To get a "light" theme without the action bar (so you can use custom title), this should work:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">false</item>
</style>
相关推荐
最新文章