在Manifest.xml中应用@ style / Base.Theme.AppCompat.Light.DarkActionBar时无法看到操作栏

时间:2015-03-25 13:38:46

标签: android xml themes android-manifest material-design

我是Android领域的首发,为了从我的老师那里获得UI分数,我希望在5.0以下的设备上获得Material Design效果,所以我添加了Android-support-V7-appcompat作为我项目的lib。

然后我更改了Manifest.xml:Theme:@ style / Base.Theme.AppCompat.Light.DarkActionBar但是通过这个动作我仍然看不到任何Actionbar。

我删除了这个主题设置,然后动画栏以Holo为主题出现,我该如何解决?

我希望具有Material Design外观的 setting.activity

  package scm.chenhyuan2.RightSpeed;

  import android.app.Activity;
  import android.content.Intent;
  import android.graphics.PorterDuff;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.Menu;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;

  public class SettingActivity extends Activity {

private static final String LOG_TAG = "SettingActivity";

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

    setContentView(R.layout.setting);

    Button mStartButton = (Button) findViewById(R.id.startButton);
    mStartButton.getBackground().setColorFilter(0x8000FF00, PorterDuff.Mode.MULTIPLY);
    mStartButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(SettingActivity.this, RunningCadenceActivity.class));
        }
    });


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.menu, menu);
    return true;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // It will only be called when returns from PreferenceActivity.
    // Restart to load in new locale in case it's changed by user.
    restartActivity();
}

private void restartActivity() {
    Log.d(LOG_TAG, "Restart activity");
    Intent intent = getIntent();
    finish();
    startActivity(intent);
}

  }

setting.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"
    android:orientation="vertical">


    <com.gc.materialdesign.views.ButtonFloat
                android:id="@+id/button00"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_margin="3dp" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:gravity="center_horizontal"
        android:text="@string/target_cadence"
        android:textSize="30sp" />

    <kankan.wheel.widget.WheelView
        android:id="@+id/targetCadence"
        android:layout_width="160dp"
        android:layout_gravity="center_horizontal"
        android:layout_height="wrap_content" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:gravity="center_horizontal"
        android:text="@string/steps_per_minute"
        android:textSize="30sp" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="2" />

    <Button
        android:id="@+id/startButton"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/start"
        android:textColor="#D0D0D0"
        android:textSize="30sp" />

</LinearLayout>

最后是Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="scm.chenhyuan2.RightSpeed"
    android:versionCode="1"
    android:versionName="assignment2" >
    <uses-sdk android:minSdkVersion="11" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:name="scm.chenhyuan2.RightSpeed.Application" android:theme="@style/Base.Theme.AppCompat.Light.DarkActionBar">

        <activity android:name="scm.chenhyuan2.RightSpeed.SettingActivity" > 
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:launchMode="singleTop"
            android:name="scm.chenhyuan2.RightSpeed.RunningCadenceActivity" />

        <activity android:name="scm.chenhyuan2.RightSpeed.PreferenceActivity" />

        <service android:name="scm.chenhyuan2.RightSpeed.BackgroundService" />

    </application>

</manifest>

1 个答案:

答案 0 :(得分:0)

如果您要使用appcompat-v7,则必须继承ActionBarActivity,而不是Activity