2016-12-01 13 views
1

Googleハングアウトappenのように下部にポップアップ表示するTextViewを作成しようとしています。 Googleハングアウトアプリでは、xxxとしてログインしたことを示すメッセージが数秒間表示されます。NavigationViewのDrawerLayout内にポップアップTextViewを表示するには

あなたは私がLinearLayoutTextViewを入れて、私はview.animate()を行うときに、それが現れないが、それはレイアウトを押し上げると、私はそれが滞在したい見ての通り、私はこの古典的なナビゲーションドロワーレイアウト

<android.support.v4.widget.DrawerLayout 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/drawer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="com.port.android.ui.ActivityMain"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <include 
      android:id="@+id/toolbar" 
      layout="@layout/tool_bar" /> 

     <FrameLayout 
      android:id="@+id/frame" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1"> 
     </FrameLayout> 

     <TextView 
      android:id="@+id/popup_logged_in" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@color/PrimaryColor" 
      android:layout_alignParentBottom="true" 
      android:padding="15dp" 
      android:textSize="14sp" 
      android:visibility="gone" 
      android:gravity="center" 
      android:textColor="@android:color/white" 
      android:textAllCaps="true" 
      android:textStyle="bold" /> 

    </LinearLayout> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/navigation_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     app:headerLayout="@layout/navigation_view_header" 
     app:menu="@menu/menu_navigation"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom" 
      android:padding="20dp" 
      android:orientation="horizontal"> 
      <Button 
       android:id="@+id/btn_exit" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:onClick="exitAddress" 
       android:text="Exit Address"/> 

     </LinearLayout> 
    </android.support.design.widget.NavigationView> 
</android.support.v4.widget.DrawerLayout> 

を持っています上。 だから私はRelativeLayoutを試していますが、それはツールバーを消してしまいました。

Here's AppCompatActivityそれは場合に役立ちます:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    if (Application.getInstance().isClosing()) 
     finish(); 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    popUpThreadPoolFactory = new PopUpThreadPoolFactory(this); 
    fragManager = getSupportFragmentManager(); 
    mMainAdapter = new ActivityMainAdapter(this); 
    // Initializing Toolbar and setting it as the actionbar 
    mToolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(mToolbar); 
    //Initializing NavigationView 
    mNavigationView = (NavigationView) findViewById(R.id.navigation_view); 
    mNavigationView.setNavigationItemSelectedListener(this); 
    // Initializing Drawer Layout and ActionBarToggle 
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer); 
    ((Button) findViewById(R.id.btn_exit)).setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      FirebaseManager.getInstance().exitCurrentAddress(); 
     } 
    }); 

    mActionBarDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.openDrawer, R.string.closeDrawer) { 
     @Override 
     public void onDrawerClosed(View drawerView) { 
      // Code here will be triggered once the drawer closes as we dont want anything to happen so we leave this blank 
      super.onDrawerClosed(drawerView); 
     } 

     @Override 
     public void onDrawerOpened(View drawerView) { 
      // Code here will be triggered once the drawer open as we dont want anything to happen so we leave this blank 
      super.onDrawerOpened(drawerView); 
     } 
    }; 
    //Setting the actionbarToggle to drawer layout 
    mDrawerLayout.addDrawerListener(mActionBarDrawerToggle); 
    //calling sync state is necessay or else your hamburger icon wont show up 
    mActionBarDrawerToggle.syncState(); 
    // Initialize Firebase Analytics 
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); 

    // ATTENTION: This was auto-generated to implement the App Indexing API. 
    // See https://g.co/AppIndexing/AndroidStudio for more information. 
    client2 = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); 
} 

@Override 
protected void onStart() { 
    super.onStart(); 
    // ATTENTION: This was auto-generated to implement the App Indexing API. 
    // See https://g.co/AppIndexing/AndroidStudio for more information. 
    client2.connect(); 
    // ATTENTION: This was auto-generated to implement the App Indexing API. 
    // See https://g.co/AppIndexing/AndroidStudio for more information. 
    Action viewAction = Action.newAction(
      Action.TYPE_VIEW, // TODO: choose an action type. 
      "ActivityMain Page", // TODO: Define a title for the content shown. 
      // TODO: If you have web page content that matches this app activity's content, 
      // make sure this auto-generated web page URL is correct. 
      // Otherwise, set the URL to null. 
      Uri.parse("http://host/path"), 
      // TODO: Make sure this auto-generated app URL is correct. 
      Uri.parse("android-app://com.port.android/http/host/path") 
    ); 
    AppIndex.AppIndexApi.start(client2, viewAction); 
} 

@Override 
protected void onResume() { 
    super.onResume(); 
    MyLog.i(TAG, "onResume"); 
    Application.getInstance().addUIListener(OnConnectionStateListener.class, this); 
    Application.getInstance().addUIListener(OnExitAddressListener.class, this); 
    Application.getInstance().addUIListener(OnUserSignedInListener.class, this); 
    // update state 
    if (Application.getInstance().isInitialized() && !Application.getInstance().isClosing()) { 
     MyLog.i(TAG, "Application isInitialized activating adapter"); 
     mainAdapterOnChange(); 
    } else 
     MyLog.i(TAG, "Wait for loading or closing"); 
} 
+0

あなたはactivty.xmlを投稿できます –

+0

ありがとう、私はアクティビティコードを追加しました –

答えて

2

を私はあなたがスナックバーについて検索していると思います。。これがあなたが試みているものなら、ここに例があります。あなたのactivity.javaクラスでは、あなたのactivity.xml

<android.support.design.widget.CoordinatorLayout  
    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:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
android:id="@+id/cd" 
tools:context="com.example.ayyappaboddupalli.dragmaker.MainActivity"> 


あなたがこれを表示したいあなた活動に

、あなたの親Layout.Supposeをバインド

CoordinatorLayout cd=(CoodinatorLayour)findViewById(R.id.cd); 

ボタンのクリックでそのポップアップを表示する場合:

btn.setOnClickListener(new onClickListener() 

    public void onClick(View v) 
    { 
    Snackbar.make(cd,"text you want to show",Snackbar.LENGTH_LONG).show(); 
    } 
    ); 
+0

「Snackbar」はそれを試してみることは決してありませんでした。考えてみると、すべてのシステムメッセージとカスタムメッセージがポップアップに表示されます。すべては 'ConcurrentLinkedQueue'と' Thread'で制御されます。基本的に私はこのようなメッセージを送ることができます - 'showPopup(text、duration、style);' Snackbarが役立つかどうかわかりませんがテストします –

+0

ありがとう[snackbar](https://www.youtube.com/watch ?v = KGS7O2wzz_Y)は私の友だちです –

+0

はい私はすばらしい速い答えです –

関連する問題