我正在制作一个带有 2 个菜单项的夏洛克操作栏。但是在操作栏的视图中,这两个项目都存在于最左侧的位置。我想在操作栏的最左侧添加 1 个菜单项以及一个文本在操作栏的中心。这是代码:
package naseeb.bar;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockActivity;
public class NaseebactionbarActivity extends SherlockActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newlayout);
ActionBar actionbar = getSupportActionBar();
actionbar.setDisplayShowTitleEnabled(false);
actionbar.setDisplayShowHomeEnabled(false);
actionbar.show();
}
public void newclickhandler(View view)
{
Toast.makeText(NaseebactionbarActivity.this, "press the button to choose the time limit for the timer", Toast.LENGTH_LONG).show();
Intent intent = new Intent(NaseebactionbarActivity.this,controltransfer.class);
startActivity(intent);
}
@Override
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu ) {
com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item){
// same as using a normal menu
switch(item.getItemId()) {
case R.id.menu1:
LayoutInflater inflater=getLayoutInflater();
View view = inflater.inflate(R.layout.main,null);
view.setMinimumWidth(200);
view.setMinimumHeight(200);
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setView(view);
alertDialog.show();
break;
case R.id.menu2:
Intent intent = new Intent(NaseebactionbarActivity.this,controltransfer.class);
startActivity(intent);
break;
}
return true;
}
public void makeToast(String message) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}
}
请告诉我如何解决这个问题。