在Manifest.xml中应用@style/Base.Theme.AppCompat.Light.DarkActionBar时看不到Action Bar
Action Bar can not be seen when applying @style/Base.Theme.AppCompat.Light.DarkActionBar in Manifest.xml
我是Android领域的初学者,为了得到老师的UI分数,我想在5.0以下的设备上有Material设计效果,所以我添加Android-support-V7-appcompat 作为我项目的库。
然后我更改了 Manifest.xml:Theme:@style/Base.Theme.AppCompat.Light.DarkActionBar 但是通过这个操作我仍然看不到任何 Actionbar.
我删除了这个主题设置,然后操作栏出现了 Holo 主题,我该如何解决?
setting.activity我想要Material设计
的样子
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>
如果您要使用 appcompat-v7
,则必须继承自 ActionBarActivity
,而不是 Activity
。
我是Android领域的初学者,为了得到老师的UI分数,我想在5.0以下的设备上有Material设计效果,所以我添加Android-support-V7-appcompat 作为我项目的库。
然后我更改了 Manifest.xml:Theme:@style/Base.Theme.AppCompat.Light.DarkActionBar 但是通过这个操作我仍然看不到任何 Actionbar.
我删除了这个主题设置,然后操作栏出现了 Holo 主题,我该如何解决?
setting.activity我想要Material设计
的样子 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>
如果您要使用 appcompat-v7
,则必须继承自 ActionBarActivity
,而不是 Activity
。