[Image sample][1]I have popup screen implemented in my navigation drawer activity. Problem is that popup window is showing like background image of activity. What i want to popup come visible in foreground when Activity starts and after 3 seconds dismiss.
Here is my activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
try {
LayoutInflater inflater1 = (LayoutInflater) MainActivity.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// Inflate the view from a predefined XML layout
View layout = inflater1.inflate(R.layout.activity_pop_up,
(ViewGroup) findViewById(R.id.relativeLayoutZaFragment));
// create a 300px width and 470px height PopupWindow
pw = new PopupWindow(layout, 300, 470, true);
// display the popup in the center
pw.showAtLocation(layout, Gravity.CENTER, 0, 0);
} catch (Exception e) {
e.printStackTrace();
}
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
FragmentMainPage pocetnaFragment = new FragmentMainPage();
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.relativeLayoutZaFragment, pocetnaFragment, "1");
fragmentTransaction.commit();
getSupportActionBar().setTitle("Auto magazin");
ActionBar.LayoutParams p = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
p.gravity = Gravity.LEFT;
view = getLayoutInflater().inflate(R.layout.action_bar, null);
ActionBar.LayoutParams params = new ActionBar.LayoutParams(
ActionBar.LayoutParams.WRAP_CONTENT,
ActionBar.LayoutParams.MATCH_PARENT,
Gravity.LEFT);
TextView Title = (TextView) view.findViewById(R.id.actionbar_title);
Title.setText("Auto magazin");
getSupportActionBar().setCustomView(view,params);
getSupportActionBar().setDisplayShowCustomEnabled(true); //show custom title
getSupportActionBar().setDisplayShowTitleEnabled(false); //hide the default title
}
boolean doubleBackToExitPressedOnce = false;
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
assert drawer != null;
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
return;
}
else if (doubleBackToExitPressedOnce) {
super.onBackPressed();
return;
}
this.doubleBackToExitPressedOnce = true;
Toast.makeText(this, "Pritisnite još jednom za izlaz", Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
doubleBackToExitPressedOnce = false;
}
}, 2000);
}
@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;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.podesavanja)
{
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.pocetna) {
FragmentMainPage fragmentMainPage = new FragmentMainPage() ;
FragmentManager manager = getSupportFragmentManager();
manager.beginTransaction().replace(R.id.relativeLayoutZaFragment
, fragmentMainPage, fragmentMainPage.getTag()).addToBackStack(null).commit();
TextView Title = (TextView) view.findViewById(R.id.actionbar_title);
Title.setText("Auto magazin");
}
else if (id == R.id.info) {
FragmentMenuPages fragmentMenuPages = new FragmentMenuPages();
FragmentManager manager = getSupportFragmentManager();
manager.beginTransaction().replace(R.id.relativeLayoutZaFragment
, fragmentMenuPages, fragmentMenuPages.getTag()).commit();
TextView Title = (TextView) view.findViewById(R.id.actionbar_title);
Title.setText("Info");
Bundle bundle = new Bundle();
bundle.putString("href","http://www.magazinauto.com/category/info/");
bundle.putString("title", "Info");
fragmentMenuPages.setArguments(bundle);
}
else {
return super.onOptionsItemSelected(item);
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
activity_pop_up:
<RelativeLayout 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"
android:id="@+id/popup"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.bolt.automagazin.PopUp">
<ImageView
android:id="@+id/imageView3"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
app:srcCompat="@drawable/autojedan" />
</RelativeLayout>
content_main.xml:
<RelativeLayout 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"
android:id="@+id/relativeLayoutZaFragment"
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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.bolt.automagazin.MainActivity"
tools:showIn="@layout/app_bar_main"
>