我知道有两种设置活动标题的方法.一种方法是在android清单中设置它,如android:label ="@ string/app_name".第二个是在活动类中以编程方式设置,如setTitle("Hello World!").两种方式都位于左侧,但我如何将其放在中心?
在我的onCreate()中,我设置了一个进度条,如下所示:
getWindow().requestFeature(Window.FEATURE_PROGRESS);
getWindow().setFeatureInt( Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
Run Code Online (Sandbox Code Playgroud)
现在,希望稍微增强标题栏,我想改变它的背景颜色.第一步是检查是否FEATURE_CUSTOM_TITLE支持:
final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
if ( customTitleSupported ) {
Log.i(TAG, "CUSTOM TITLE SUPPORTED!")
}
Run Code Online (Sandbox Code Playgroud)
但是一旦我打电话给requestWindowFeature(Window.FEATURE_CUSTOM_TITLE)我得到一个:
AndroidRuntimeException: You cannot combine custom titles with other title features
Run Code Online (Sandbox Code Playgroud)
(如果我在设置之前FEATURE_PROGRESS或之后调用此函数无关紧要)
知道如何解决这个问题吗?
或者,如果我能找到非自定义标题栏的资源ID,我会避免使用自定义标题栏.比危险的getParent()更好的东西.
这可能吗?