我搜索了高低,找到一种简单的方法将按钮变成菜单(任何菜单样式)我目前在我的应用程序中有按钮,我想将它们变成菜单(即右边的3个点)角落)以获得更简单的用户界面
我希望以下内容出现在菜单中: bCheckOnline bSettings bLogout1
如果这比我想象的要复杂得多,请与我联系,我会付钱给别人修改我的代码。 (但是,任何帮助都表示赞赏!)
我在下面包含了我的res / layout / activity_main.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"
android:scrollbars="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:background="@color/black"
android:paddingBottom="@dimen/sixteen"
android:paddingTop="@dimen/sixteen"
android:weightSum="10" >
<TextView
android:id="@+id/tvSyncDate_temp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:visibility="gone" />
<TextView
android:id="@+id/tvVersion"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="9.06"
android:gravity="center_vertical"
android:paddingLeft="13dp"
android:singleLine="true"
android:textColor="@color/white"
android:text="TAP+REPORT"
android:textSize="@dimen/twentysize"
android:textStyle="bold" />
<Button
android:id="@+id/bSettings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.55"
android:background="@drawable/btn2"
android:text="Sync"
android:textColor="@color/white"
android:textSize="@dimen/twentysize" />
</LinearLayout>
<ScrollView
android:id="@+id/svMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:scrollbars="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:background="@color/white"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/tvVersion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingLeft="@dimen/thirteen"
android:paddingRight="@dimen/thirteen"
android:paddingTop="5dp"
android:text="Tap tag now with top-back of phone and hold to report. Upon completion tap sync."
android:textColor="@color/darkgrey"
android:textSize="@dimen/seventeen" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="10dp" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_weight="4.76"
android:gravity="top|center_vertical|center_horizontal"
android:orientation="vertical" >
<ImageView
android:id="@+id/myanimation"
android:layout_width="match_parent"
android:layout_height="338dp"
android:padding="15dp"
android:scaleType="fitCenter"
android:src="@anim/anim_android" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="bottom"
android:orientation="horizontal"
android:paddingBottom="@dimen/twentysize"
android:paddingLeft="@dimen/twentysize"
android:paddingRight="@dimen/twentysize" >
<Button
android:id="@+id/bCheckOnline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="8.55"
android:background="@drawable/btn3"
android:text="View Online"
android:textColor="@color/darkgrey"
android:textSize="@dimen/seventeen" />
<Button
android:id="@+id/bLogout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="4"
android:background="@null"
android:gravity="right|center_horizontal"
android:paddingRight="5dp"
android:text="Logout"
android:textColor="@color/holobluelight"
android:textSize="@dimen/seventeen" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
</LinearLayout>
我已经包含了java文件:
package com.test.test.activity;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
//import android.provider.Contacts.Intents;
import android.widget.TextView;
import java.util.Random;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
import android.net.Uri;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.client.methods.HttpPost;
import java.io.IOException;
import android.nfc.NdefMessage;
import android.nfc.NfcAdapter;
import android.os.Parcelable;
import android.util.Log;
//import org.ndeftools.Message;
//import org.ndeftools.Record;
//import org.ndeftools.wellknown.SmartPosterRecord;
//import org.ndeftools.wellknown.TextRecord;
//import org.ndeftools.wellknown.UriRecord;
import android.app.PendingIntent;
import android.content.IntentFilter;
import android.content.IntentFilter.MalformedMimeTypeException;
import android.nfc.Tag;
import android.nfc.tech.Ndef;
import android.graphics.drawable.AnimationDrawable;
import android.widget.ImageView;
public class ScanInputActivity extends Activity implements OnClickListener {
SharedPreferences app_preferences;
TextView tvSyncDate_temp;
Vehicle vehicle;
private NfcAdapter mNfcAdapter;
public static final String MIME_TEXT_PLAIN = "text/plain";
public static final String TAG = "NfcDemo";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView myAnimation = (ImageView)findViewById(R.id.myanimation);
final AnimationDrawable myAnimationDrawable
= (AnimationDrawable)myAnimation.getDrawable();
myAnimation.post(
new Runnable(){
@Override
public void run() {
myAnimationDrawable.start();
}
});
Button bSettings= (Button) findViewById(R.id.bSettings);
bSettings.setOnClickListener(this);
Button bCheckOnline= (Button) findViewById(R.id.bCheckOnline);
bCheckOnline.setOnClickListener(this);
Button bLogout1 = (Button) findViewById(R.id.bLogout1);
bLogout1.setOnClickListener(this);
感谢先进的人!
答案 0 :(得分:0)
您需要扩展活动的ActionBarActivity
内容。
然后为onCreateOptionsMenu
创建一个函数@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
然后制作onOptionsItemSelected
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
// Do something when Settings button is clicked.
return true;
}
return super.onOptionsItemSelected(item);
}
在你的Resourses文件夹中必须有一个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="com.example.test.MainActivity" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never"/>
</menu>
您可以使用上面的代码进行试验并修改它以获得所需的结果。我希望这些信息有用。详细了解here.