Hello目前正在我的Android应用程序上实现操作栏。
尝试添加此溢出图像。
我正在尝试遵循官方文档。 http://developer.android.com/guide/topics/ui/actionbar.html#Adding
然而,当我运行我的应用程序时,我的屏幕显示如下,没有动作栏的图像
不确定我做错了什么。
这是我的main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity" >
<item android:id="@+id/action_overflow"
android:title="@string/action_settings"
android:orderInCategory="100"
android:icon="@drawable/ic_action_overflow"
app:showAsAction="always" />
</menu>
这是我的MainActivity.java的
的java代码package com.spicycurryman.getdisciplined10.app;
import android.content.pm.ActivityInfo;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import com.triggertrap.seekarc.SeekArc;
import com.triggertrap.seekarc.SeekArc.OnSeekArcChangeListener;
public class MainActivity extends ActionBarActivity {
private SeekArc mSeekArc;
private SeekBar mRotation;
private SeekBar mStartAngle;
private SeekBar mSweepAngle;
private SeekBar mArcWidth;
private SeekBar mProgressWidth;
private CheckBox mRoundedEdges;
private CheckBox mTouchInside;
private CheckBox mClockwise;
private TextView mSeekArcProgress;
private Button block_button_text;
private Button security_settings_button_text;
private Button blacklist_whitelist_button_text;
@Override
protected void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
super.onCreate(savedInstanceState);
setContentView(R.layout.merge);
//Editing Button Text
block_button_text = (Button)findViewById(R.id.block_button);
block_button_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/roboto-light.ttf"));
security_settings_button_text = (Button)findViewById(R.id.security_settings_button);
security_settings_button_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/roboto-light.ttf"));
blacklist_whitelist_button_text = (Button)findViewById(R.id.blacklist_whitelist_button);
blacklist_whitelist_button_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/roboto-light.ttf"));
mSeekArc = (SeekArc) findViewById(R.id.seekArc);
mSeekArcProgress = (TextView) findViewById(R.id.seekArcProgress);
mRotation = (SeekBar) findViewById(R.id.rotation);
mStartAngle = (SeekBar) findViewById(R.id.startAngle);
mSweepAngle = (SeekBar) findViewById(R.id.sweepAngle);
mArcWidth = (SeekBar) findViewById(R.id.arcWidth);
mProgressWidth = (SeekBar) findViewById(R.id.progressWidth);
mRoundedEdges = (CheckBox) findViewById(R.id.roundedEdges);
mTouchInside = (CheckBox) findViewById(R.id.touchInside);
mClockwise = (CheckBox) findViewById(R.id.clockwise);
mRotation.setProgress(mSeekArc.getArcRotation());
mStartAngle.setProgress(mSeekArc.getStartAngle());
mSweepAngle.setProgress(mSeekArc.getSweepAngle());
mArcWidth.setProgress(mSeekArc.getArcWidth());
mProgressWidth.setProgress(mSeekArc.getProgressWidth());
mSeekArc.setOnSeekArcChangeListener(new OnSeekArcChangeListener() {
@Override
public void onStopTrackingTouch(SeekArc seekArc) {
}
@Override
public void onStartTrackingTouch(SeekArc seekArc) {
}
@Override
public void onProgressChanged(SeekArc seekArc, int progress,
boolean fromUser) {
mSeekArcProgress.setText(String.valueOf(progress));
}
});
mRotation.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar arg0) {
}
@Override
public void onStartTrackingTouch(SeekBar arg0) {
}
@Override
public void onProgressChanged(SeekBar view, int progress, boolean fromUser) {
mSeekArc.setArcRotation(progress);
mSeekArc.invalidate();
}
});
mStartAngle.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar arg0) {
}
@Override
public void onStartTrackingTouch(SeekBar arg0) {
}
@Override
public void onProgressChanged(SeekBar view, int progress, boolean fromUser) {
mSeekArc.setStartAngle(progress);
mSeekArc.invalidate();
}
});
mSweepAngle.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar arg0) {
}
@Override
public void onStartTrackingTouch(SeekBar arg0) {
}
@Override
public void onProgressChanged(SeekBar view, int progress, boolean fromUser) {
mSeekArc.setSweepAngle(progress);
mSeekArc.invalidate();
}
});
mArcWidth.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar arg0) {
}
@Override
public void onStartTrackingTouch(SeekBar arg0) {
}
@Override
public void onProgressChanged(SeekBar view, int progress, boolean fromUser) {
mSeekArc.setArcWidth(progress);
mSeekArc.invalidate();
}
});
mProgressWidth.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar arg0) {
}
@Override
public void onStartTrackingTouch(SeekBar arg0) {
}
@Override
public void onProgressChanged(SeekBar view, int progress, boolean fromUser) {
mSeekArc.setProgressWidth(progress);
mSeekArc.invalidate();
}
});
mRoundedEdges.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
mSeekArc.setRoundedEdges(isChecked);
mSeekArc.invalidate();
}
});
mTouchInside.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
mSeekArc.setTouchInSide(isChecked);
}
});
mClockwise.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
mSeekArc.setClockwise(isChecked);
mSeekArc.invalidate();
}
});
}
}
答案 0 :(得分:0)
您需要在活动中使用onCreateOptionsMenu方法加载xml文件
例如:
menu1.xml(在res / menu中保存此xml文件)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/item1"
android:icon="@drawable/xyz"
android:showAsAction="always" />
</menu>
现在像这样加载xml文件:
public boolean onCreateOptionsMenu(Menu menu){
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu1, menu);
return true;
}
答案 1 :(得分:0)
尝试查看此方法:在OnCreate()中调用此方法,
private void getOverflow() {
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKey = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if(menuKey != null) {
menuKey.setAccessible(true);
menuKey.setBoolean(config, false);
}
} catch (Exception e) {
e.printStackTrace();
}
}