本人新建的Activity为什么没有标题栏

Android 码拜 7年前 (2017-04-22) 1680次浏览
新建个项目,选择Empty Activity,然后本人又添加一个 Activity,但是没有标题栏,怎么回事。
就在本人发这个贴的时候,本人又 rebuild 了一下项目,现在两个 activity 都没标题栏了。蛋疼!

<!-- m1.xml -->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="启动第二个Activity"
        android:id="@+id/bt1" />
</LinearLayout>
<!-- m2.xml -->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="返回"
        android:id="@+id/bt2" />
</LinearLayout>
//MainActivity.java
package com.example.administrator.first;
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.m1);
        Button b = (Button)findViewById(R.id.bt1);
        b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i = new Intent(MainActivity.this, SecondActivity.class);
                startActivity(i);
            }
        });
    }
}
//SecondActivity.java
package com.example.administrator.first;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
/**
 * Created by Administrator on 2016/10/12.
 */
public class SecondActivity extends Activity
{
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.m2);
    }
}
<!-- AndroidManifext.xml -->
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.administrator.first">
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".SecondActivity">
        
        </activity>
    </application>
</manifest>

本人新建的Activity为什么没有标题栏
本人新建的Activity为什么没有标题栏

解决方案

7

是不是在

android:theme="@style/AppTheme"

里面隐藏的标题栏。

7

你看下你 AppTheme 下面是不是有这句话

<item name="android:windowNoTitle">true</item>

有就把true改为false

6

    android:theme=”@style/AppTheme”>
点进去看看parent的设置,能否设置了没标题
<style name=”AppTheme” parent=”Theme.AppCompat.Light.DarkActionBar”>
<!– Customize your theme here. –>
<item name=”colorPrimary”>@color/colorPrimary</item>
<item name=”colorPrimaryDark”>@color/colorPrimaryDark</item>
<item name=”colorAccent”>@color/colorAccent</item>
</style>

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明本人新建的Activity为什么没有标题栏
喜欢 (0)
[1034331897@qq.com]
分享 (0)