2016-08-27 4 views
0

android studio에서 제공하는 제목 표시 줄 대신 사용자 지정 제목 표시 줄을 만들려고합니다.사용자 지정 제목 표시 줄과 원본 제목 표시 줄이 모두 나타납니다.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.example.hsports.fragmentsinandroid.MainActivity"> 


    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:id="@+id/textTitle" 
     android:text="CustomTitle" 

     /> 


    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/duck" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentRight="true" 
     /> 



</RelativeLayout> 

그리고 내 MainActivity 클래스는 다음과 같습니다 : 내 activity_main.xml이다

package com.example.hsports.fragmentsinandroid; 

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.Window; 

public class MainActivity extends AppCompatActivity { 

    @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.activity_main); 
    } 
} 

내 style.xml은 다음과 같습니다

<resources> 

    <!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 
    </style> 

    <style name="CustomTheme" parent="@style/Theme.AppCompat"> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 

     <item name="android:windowNoTitle">false</item> 
    </style> 
</resources> 

내의 AndroidManifest.xml 파일은 다음과 같습니다

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.hsports.fragmentsinandroid"> 

    <application 
android:allowBackup="true" 
android:icon="@mipmap/ic_launcher" 
android:label="@string/app_name" 
android:supportsRtl="true" 
android:theme="@style/CustomTheme"> 
<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> 

어미스트 어 안드로이드 응용 프로그램에 대한 위의 코드를 사용하여 나는 스크린 샷에 첨부 된 출력을 받고있다. 첨부 된 스크린 샷을보십시오. 제목 표시 줄 (사용자 정의 + 원본)이 모두 표시됩니다. 나는 사용자 정의 된 것을 나타 내기만을 원한다. the attached screenshot is here.

+0

가능한 복제를 사용하지 않도록하는 것이 필요 [ Window.FEATURE \ _CUSTOM \ _TITLE 사용하려고하지만 예외 : 사용자 정의 제목을 다른 제목 기능과 결합 할 수 없습니다 ..] (http://stackoverflow.com/questions/2686556/try-to-use-window-feature-custom - 그러나 - 예외 - 당신 can not-combine-cust) –

+0

오류 메시지를 검색하면 가능한 해결책을 찾는 데 도움이됩니다. –

답변

0

당신이 테마에서 사용자 정의 제목을 사용하려면이 cannot combine custom titles with other title features

당신이 사용자 지정 테마

<item name="android:windowNoTitle">false</item>을 사용해야 확인 않았다, 그것의 FEATURE_NO_TITLE

+0

당신은 질문을 다시 볼 수 있습니까? 나는 약간의 편집을했다. –

관련 문제