且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

活动不显示Android Studio中的标题栏

更新时间:2022-12-19 18:54:17

你所面对的是关系到API中的错误22(5.1)SDK。

请参见在其中不显示操作栏的错误的详细信息,以下链接:


  1. HTTPS://$c$c.google。 COM / p /安卓/问题/细节?ID = 159793

  2. HTTPS://$c$c.google。 COM / p /安卓/问题/细节?ID = 159780

你可以现在做什么


  1. 要么恢复到21 API如果可能的话,或者

  2. 在与(与渲染)编译选择API 21 Android Studio中的选项。

希望这有助于。

I have create demo application in Android Studio with two Activity. In First Activity Show Title Bar in preview as well as in emulator but on second Activity does not show Title Bar in Emulator but it display in preview. I have used API 22 in Android Studio. Please help me....thanx in advn

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/BaseTheme">
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".DrawingActivity"
        android:label="@string/app_name"
        android:theme="@style/BaseTheme"
        android:screenOrientation="portrait" />
</application>

Theme style file like this....

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->

</style>

<style name="BaseTheme" parent="AppTheme">
    <item name="colorPrimary">@color/action_bar_backgound</item>
</style>

I have also try this... First Activity Work's fine so I have set that in Second Activity as a setContentView(R.layout.activity_main);

MainActivity.java

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void buttonAction(View v) {
        Intent intent = new Intent(MainActivity.this, DrawingActivity.class);
        startActivity(intent);
    }
}

DrawActivity.java

public class DrawingActivity extends Activity {


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

        setContentView(R.layout.activity_main);

    }
}

What you are facing is a bug related to the API 22(5.1) SDK.

Kindly refer the following links for the details on the bug in which the Action Bar is not displayed:

  1. https://code.google.com/p/android/issues/detail?id=159793
  2. https://code.google.com/p/android/issues/detail?id=159780

What you can do for now

  1. Either revert back to API 21 if possible or,
  2. Select API 21 in the compile with (render with) option in Android Studio.

Hope this helps.