Android的活动只在主要活动不显示和无法正确显示
问题描述:
在主要活动中没有显示,而本相同的代码用于其他活动还有一件事操作栏溢出不受列表右上角
- 图像显示
行动起来吧1:具有菜单键主要活动按压
- 图像2:显示消息活动 用于主活性
代码:
public class MainActivity extends ActionBarActivity {
EditText t;
public final static String sendMessageextra="com.example.example2.textmessage";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t=(EditText) findViewById(R.id.textmessage);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main_actions, menu);
return super.onCreateOptionsMenu(menu);
}
public void sendMessage(View v){
Intent sendmessageintent=new Intent(this,showMessage.class);
String messagestring=t.getText().toString();
sendmessageintent.putExtra(sendMessageextra, messagestring);
startActivity(sendmessageintent);
}
}
显示消息活动:
public class showMessage extends Activity{
TextView t;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sendmessage);
t=(TextView) findViewById(R.id.showmessage);
showmessage();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater=getMenuInflater();
inflater.inflate(R.menu.activity_main_actions, menu);
return true;
}
public void showmessage(){
Intent intent=getIntent();
String message=intent.getStringExtra(MainActivity.sendMessageextra);
t.setText(message);
Log.i("Set New Text Box", "Text BOx");
}
}
活动主要actions.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Search Widget -->
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
android:showAsAction="ifRoom"
android:actionViewClass="android.widget.SearchView"/>
<!-- Location Found -->
<item android:id="@+id/action_location_found"
android:icon="@drawable/ic_action_location_found"
android:title="@string/action_location_found"
android:showAsAction="never" />
<!-- Help -->
<item android:id="@+id/action_help"
android:icon="@drawable/ic_action_help"
android:title="@string/action_help"
android:showAsAction="never"/>
</menu>
的Android menifest文件: 活动清单文件:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.example2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name="com.example.example2.showMessage"
android:label="Show Message" android:parentActivityName="com.example.example2.MainActivity"/>
</application>
</manifest>
答
如果要在每个活动中的操作栏右侧显示搜索图标,则只需将ac在actions.xml而不是android:showAsAction =“ifRoom”中更改为android:showAsAction =“always”
答
-
ActionBar
没有显示
在你的OnCreate做到这一点()
ActionBar actionBar = getActionBar();
actionBar.show();
-
ActionBar overflow
那里你可以看到你的菜单
要显示菜单,在您的活动主要actions.xml,
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/action_search"
android:showAsAction="always"
android:title="@string/action_search"
android:icon="@android:drawable/ic_action_search"
android:actionViewClass="android.widget.SearchView"/>
</menu>
这样你需要在主要操作文件中进行更改
这是您的清单文件中的启动器活动? – Rohit 2014-09-18 10:21:36
添加了Android清单文件....请快速帮助我#Rohit – 2014-09-25 05:24:01
FAST?这是什么意思? – nobalG 2014-09-25 05:25:01