Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android将FragmentActivity更改为具有自定义标题和显示溢出的ActionbarActivity_Android_User Interface_Android Actionbar - Fatal编程技术网

Android将FragmentActivity更改为具有自定义标题和显示溢出的ActionbarActivity

Android将FragmentActivity更改为具有自定义标题和显示溢出的ActionbarActivity,android,user-interface,android-actionbar,Android,User Interface,Android Actionbar,我真的对自定义标题和actionbaroverflow感到困惑 到目前为止,我有一个Fragmentactivity,它使用一个带有大图像的自定义标题栏和标题栏上的另外两个按钮。我现在需要使用ActionBarActivity来显示带有2个选项菜单的操作溢出Actionbaractivity是Fragmentactivity的一个子类,但是在我使用Actionbaractivity之后,onCreate()中的初始化出现问题: (equestWindowFeature(Window.FEATUR

我真的对自定义标题和
actionbar
overflow感到困惑

到目前为止,我有一个
Fragmentactivity
,它使用一个带有大图像的自定义标题栏和标题栏上的另外两个按钮。我现在需要使用
ActionBarActivity
来显示带有2个选项菜单的操作溢出
Actionbaractivity
Fragmentactivity
的一个子类,但是在我使用
Actionbaractivity
之后,
onCreate()中的初始化出现问题:

(equestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

在添加内容之前,必须调用…error requestFeature()

我搜索了
StackOverlow
,但找不到确切的答案。我认为这应该是一个非常简单的解决方案,但我找不到

public class BluetoothChat extends ActionBarActivity implements TimePickerFragment.OnTimeDialogListener
@Override
public void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.CustomTheme);
    super.onCreate(savedInstanceState);
    if (D) Log.e(TAG, "+++ ON CREATE +++");

    // using custom title to create custom title bar with bdx logo
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

    setContentView(R.layout.main);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.windows_title);
自定义标题栏主题和布局


风格:

<resources>
    <style name="CustomWindowTitleBackground">
        <item name="android:background">@color/title_color</item>
    </style>

    <style name="CustomTheme" parent="android:Theme">
        <item name="android:windowTitleSize">50dip</item>
        <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>

    </style>
</resources>

@颜色/标题\u颜色
50度
@样式/自定义窗口标题背景
菜单:


Theme.AppCompat主题

<style name="mActionBar" parent="@style/Widget.AppCompat.ActionBar">
    <item name="android:windowTitleSize">50dip</item>
    <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>

<style name="CustomTheme" parent="@style/Theme.AppCompat">
    <item name="android:actionBarStyle">@style/mActionBar</item>
    <item name="actionBarStyle">@style/mActionBar</item>
</style>

50度
@样式/自定义窗口标题背景
@风格/主题栏
@风格/主题栏
添加以下内容:

final ActionBar actionBar = getSupportActionBar();
actionBar.setCustomView(R.layout.windows_title);
而不是:

getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.windows_title);

移动getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.windows_TITLE);在setContentView(R.layout.main);@Shahzeb没有用,它在请求WindowFeature(Window.FEATURE_CUSTOM_TITLE)行上出错;通过此更改,我在“super.onCreate(savedInstanceState);”上出错。您需要使用一个Theme.AppCompat主题(或子代)使用此活动。'just replace getActionBar();to getSupportActionBar();您需要将主题的父级更改为theme.AppCompat.*。为project设置了哪个targetSDK?目标sdk为17。对于上面的theme.AppCompat更改(请参见编辑),我得到了相同的错误。从CustomTheme中删除@style/mActionBar
final ActionBar actionBar = getSupportActionBar();
actionBar.setCustomView(R.layout.windows_title);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.windows_title);