我想获得有关主要活动的帮助屏幕,以供用户指导如何使用该应用程序.
这是我的主要活动.
这是我的main_activity.xml文件组成的这段代码.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:id="@+id/button"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
这是我的mainactivity java类文件,由以下代码组成.
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@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);//Menu Resource, Menu
return true;
}
@Override
public boolean onoptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.clipboard:
Toast.makeText(getApplicationContext(),"Text copied",Toast.LENGTH_LONG).show();
return true;
default:
return super.onoptionsItemSelected(item);
}
}
}
这是main_menu.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/clipboard"
android:icon="@drawable/ic_content_copy_white_48dp"
android:orderInCategory="100"
android:title="Clip Board"
app:showAsAction="always" />
</menu>
解决方法:
这是activity_main.xml的样子
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="eflair.helperscreentutorial.MainActivity">
<Button
android:id="@+id/newButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="New Button" />
<FrameLayout
android:id="@+id/fullScreenLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
这是MainActivity.java的样子
public class MainActivity extends AppCompatActivity {
private FrameLayout fullScreenLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fullScreenLayout = (FrameLayout) findViewById(R.id.fullScreenLayout);
final RelativeLayout layout = new RelativeLayout(this); // Dynamically creating layout
layout.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams
.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
layout.setBackgroundColor(Color.DKGRAY); // Setting bgcolor to the layout
layout.setAlpha(0.5f); // Setting opacity to the layout
layout.setBackgroundResource(R.drawable.helperscreen); // Adding image to layout
layout.setonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fullScreenLayout.removeView(layout); // On clicking the image layout will be removed
}
});
fullScreenLayout.addView(layout); // Adding view to the layout
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onoptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.cb:
Toast.makeText(getApplicationContext(), "Text copied", Toast.LENGTH_LONG).show();
return true;
default:
return super.onoptionsItemSelected(item);
}
}
}
这是输出.