2012-08-09 5 views
14

about, contact 및 legal 옵션이있는 환경 설정 화면을 만들려고합니다.이 옵션을 클릭하면 blurb 및 icon 텍스트가 별도 페이지에 표시됩니다 (shared preferences 또는 그 외).환경 설정 화면에 텍스트 블록이 표시됩니다.

텍스트를 표시하기 위해 계층을 이해하는 데 문제가 있습니다. 나는 다음과 같은 흐름을 원합니다 : settings -> about -> the about text

현재 카테고리와 옵션을 제공하는이 기능이 있지만 새로운 텍스트를 표시하기 위해 무엇을해야할지 모르겠습니다.

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> 

    <PreferenceCategory 
      android:title="Info"> 
     <Preference android:title="About"/> 


    </PreferenceCategory> 
... 
</PreferenceScreen> 

clickable을 textview로 만들 때 어떤 옵션을 사용해야할지 모르겠습니다.

답변

8

형식화 된 텍스트 블록을 PreferenceScreen 안에 추가 할 수 없습니다. 그 의도가 아닙니다. 그러나 다른 활동 안에 정보 텍스트를 추가 할 수 있습니다 (LinearLayout, 일부 서식이 TextView이면 충분할 수 있음). 인 텐트를 환경 설정에 전달하여 호출하십시오.

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >  
    <Preference 
     android:key="about" 
     android:title="About">   
      <intent android:action="your.package.path.to.Activity"/>   
    </Preference> 
</PreferenceScreen> 
+0

당신이 더에 확장 할 수 있습니까? 텍스트 블록을 표시하기 위해 활동의 의도를 불러야합니까? – Nick

+0

글쎄, 텍스트 블록 자체는 환경 설정 페이지에있는 것이 아닙니다. (서식없는 텍스트 만 표시하는) 요약을 추가하지 않는 한, 유일한 옵션은 새 활동을 열거 나 기본 설정 페이지가 아닌 about 페이지를 다른 것으로 정의하는 것입니다. – Korcholis

+0

알겠습니다. 무슨 뜻인지 알 겠어. 클릭하면 다른 환경 설정으로 이동하여 제목과 요약을 사용하여 단일 의도로 텍스트를 표시하도록 설정할 수 있습니까? 기본적으로 기본 환경 설정 화면에서 "정보"를 클릭했을 때 표시 될 다른 XML 환경 설정 파일을 만드시겠습니까? – Nick

22

동일한 문제가있어서 정적 텍스트 블록을 표시해야합니다. 내 경우에는 환경 설정 페이지에 줄 지어 있었지만.

태그는 정적 텍스트의 필요성을 해결하지 못하더라도 링크 할 수 있습니다. 그러나 기본 설정 태그 자체가 있습니다. 텍스트, 일반적인 제목 줄 및 텍스트 요약을 아래에 표시 할 수 있습니다. 둘 다 선택 사항이며 선택을 취소 할 수 있습니다. 그것은 정적 텍스트의 환상을 줄 것이다.

<Preference 
    android:key="pref_static_field_key" 
    android:selectable="false" 
    android:title="you can omit the title" 
    android:summary="Multi line description\ncan go here."/> 
+0

참고 : 환경 설정 태그에는 android : fragment라는 속성이 있습니다.이 속성은 기본 설정 조각에 연결되어있는 것으로 보입니다. 위와 결합하면 About 상자에 필요한 것처럼 보입니다. –

25

A.Grandt의 솔루션은 환경 활동 내의 텍스트 블록의 정말 좋은 모방을 제공합니다,하지만 난 불필요 앱의 설정을 된 SharedPreferences 파일에이 '가상 환경'을 저장 피하는 android:persistent="false" 속성을 추가합니다.

요약하면. A.Grandt 등의 환경 활동 내에서 텍스트 뷰의 모방 될 것이다 제안 :

<Preference 
    android:key="pref_static_field_key" 
    android:selectable="false" 
    android:persistent="false" 
    android:title="you can omit the title" 
    android:summary="Multi line description\ncan go here."/> 

당신이 줄 바꿈에 대한 \n을 사용할 수 있습니다, 아직이 기본 설정 항목 자체의 크기를 조정하지는 않지만, 그래서 가능성이 있습니다 이들 multilines 것 여전히 단일 라인 환경 설정 항목 내에서 완전히 보일 수 없습니다.

+0

이 방법을 사용하면 텍스트 블록 값 (요약) *을 코드 *로 설정할 수 있습니까? (사용 사례 : 환경 설정 화면 상단에 응용 프로그램 버전 이름을 표시하십시오.) – Jonik

+0

[매우 쉽게 밝혀졌다] (http://stackoverflow.com/a/43371960/56285); 코드에서 환경 설정을 찾고 환경 설정의 요약을 설정하십시오. – Jonik

3

텍스트 블록을 추가하고 싶지만 은 실제 텍스트 콘텐츠를 프로그래밍 방식으로 설정합니다. 내 구체적인 필요성 : 환경 설정 화면 상단에 앱 버전 이름을 표시하십시오.

접근 방식에 따라 A.GrandtKrzysiek으로 완료하고 코드에 요약을 설정했습니다.

dev_preferences.xml

:

<Preference 
    android:key="pref_app_version" 
    android:persistent="false" 
    android:selectable="false" 
    android:title="@string/app_name" /> 

선호 조각 (extends PreferenceFragment) : 나는 또한 <Preference> 항목에 android:layout="@layout/dev_preferences_header"을 설정하여 사용자 정의 레이아웃 (as in this answer)를 사용하여 결국

private static final String KEY_APP_VERSION = "pref_app_version"; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     addPreferencesFromResource(R.xml.dev_preferences); 

     findPreference(KEY_APP_VERSION).setSummary(BuildConfig.VERSION_NAME); 
    } 

.(필수 아니,하지만이 방법으로 쉽게 선호 "헤더"의 모양을 사용자 정의 할 수 있습니다.)

dev_preferences_header.xml

:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"  
    android:minHeight="?android:attr/listPreferredItemHeight" 
    android:padding="@dimen/spacing_small"> 

    <TextView 
     android:id="@android:id/title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <TextView 
     android:id="@android:id/summary" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@android:id/title" /> 

</RelativeLayout> 
관련 문제