컨텐츠를 추가하기 전에 requestFeature ()를 호출해야합니다.
맞춤 제목 표시 줄을 구현하려고합니다.
내 도우미 클래스는 다음과 같습니다.
import android.app.Activity;
import android.view.Window;
public class UIHelper {
public static void setupTitleBar(Activity c) {
final boolean customTitleSupported = c.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
c.setContentView(R.layout.main);
if (customTitleSupported) {
c.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);
}
}
}
다음은 onCreate ()에서 호출하는 위치입니다.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setupUI();
}
private void setupUI(){
setContentView(R.layout.main);
UIHelper.setupTitleBar(this);
}
하지만 오류가 발생합니다.
requestFeature() must be called before adding content
글쎄, 오류 메시지가 알려주는 것을 수행하십시오.
setContentView()
전에 전화하지 마십시오 requestFeature()
.
노트 :
의견에서 말했듯이 ActionBarSherlock
, AppCompat
도서관 과 도서관 모두 requestFeature()
전에 전화 해야합니다.super.onCreate()
나는 그것이 1 년 이상 된 것을 알고 있지만 전화를 requestFeature()
하면 내 문제가 해결되지 않았습니다. 사실 나는 그것을 전혀 부르지 않습니다.
내가 생각한보기를 팽창시키는 데 문제가있었습니다. 모든 검색에도 불구하고 뷰를 부 풀리는 다른 방법으로 놀기 전까지는 적절한 해결책을 찾지 못했습니다.
AlertDialog.Builder는 쉬운 솔루션이지만를 사용하여 onPrepareDialog()
해당 뷰를 업데이트하는 경우 많은 작업이 필요합니다 .
또 다른 대안은 대화 상자에 AsyncTask를 활용하는 것입니다.
내가 사용한 최종 솔루션은 다음과 같습니다.
public class CustomDialog extends AlertDialog {
private View content;
public CustomDialog(Context context) {
super(context);
LayoutInflater li = LayoutInflater.from(context);
content = li.inflate(R.layout.custom_view, null);
setUpAdditionalStuff(); // do more view cleanup
setView(content);
}
private void setUpAdditionalStuff() {
// ...
}
// Call ((CustomDialog) dialog).prepare() in the onPrepareDialog() method
public void prepare() {
setTitle(R.string.custom_title);
setIcon( getIcon() );
// ...
}
}
* 추가 참고 사항 :
- 제목을 숨기지 마십시오. 제목을 설정하지 않아도 빈 공간이 종종 있습니다.
- 머리글 바닥 글 및 중간 뷰를 사용하여 고유 한 뷰를 작성하지 마십시오. 위에서 언급 한 것처럼 FEATURE_NO_TITLE을 요청하더라도 헤더가 완전히 숨겨지지 않을 수 있습니다.
- 색상 속성이나 텍스트 크기로 콘텐츠보기의 스타일을 크게 지정하지 마십시오. 대화 상자에서 처리하도록하십시오. 그렇지 않으면 공급 업체가 색상을 반전시키기 때문에 검은 색 텍스트를 진한 파란색 대화 상자에 놓을 위험이 있습니다.
DialogFragment를 확장 하고 위의 답변이 작동하지 않았습니다 . 제목을 제거하려면 getDialog ()를 사용해야했습니다.
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
Doesn't the error exactly tell you what's wrong? You're calling requestWindowFeature
and setFeatureInt
after you're calling setContentView
.
By the way, why are you calling setContentView
twice?
For SDK version 23 and above, the same RuntimeException is thrown if you are using AppCompatActivity to extend your activity. It will not happen if your activity derives directly from Activity.
This is a known issue on google as mentioned in https://code.google.com/p/android/issues/detail?id=186440
The work around provided for this is to use supportRequestWindowFeature() method instead of using requestFeature().
Please upvote if it solves your problem.
Change the Compile SDK version,Target SDK version to Build Tools version to 24.0.0 in build.gradle if u face issue in request Feature
In my case I showed DialogFragment
in Activity
. In this dialog fragment I wrote as in DialogFragment remove black border:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(STYLE_NO_FRAME, 0)
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
super.onCreateDialog(savedInstanceState)
val dialog = Dialog(context!!, R.style.ErrorDialogTheme)
val inflater = LayoutInflater.from(context)
val view = inflater.inflate(R.layout.fragment_error_dialog, null, false)
dialog.setTitle(null)
dialog.setCancelable(true)
dialog.setContentView(view)
return dialog
}
Either remove setStyle(STYLE_NO_FRAME, 0)
in onCreate()
or chande/remove onCreateDialog
. Because dialog settings have changed after the dialog has been created.
I had this issue with Dialogs based on an extended DialogFragment which worked fine on devices running API 26 but failed with API 23. The above strategies didn't work but I resolved the issue by removing the onCreateView method (which had been added by a more recent Android Studio template) from the DialogFragment and creating the dialog in onCreateDialog.
참고URL : https://stackoverflow.com/questions/4250149/requestfeature-must-be-called-before-adding-content
'Programing' 카테고리의 다른 글
"코 루틴"과 "스레드"의 차이점은 무엇입니까? (0) | 2020.06.27 |
---|---|
C #에서 컴퓨터를 종료하는 방법 (0) | 2020.06.27 |
ImportError : 이름이 apiclient.discovery 인 모듈이 없습니다. (0) | 2020.06.27 |
Octave-Gnuplot-AquaTerm 오류 : 터미널 아쿠아 확장 제목“그림 1”… 알 수없는 터미널 유형 설정” (0) | 2020.06.27 |
Swift에서 빈 배열을 만드는 방법은 무엇입니까? (0) | 2020.06.27 |