2017-06-18 16 views
-2

我想製作一個按鈕或一個視圖,它能夠顯示出高於EditText的 ,當點擊該按鈕時,會對該特定焦點EditText執行某些操作。我不知道它是如何調用的,或者是否有任何3D派對庫。其他視圖上的浮動按鈕 - Android

+1

可你只是張貼圖片或東西來闡述你真正想要的是什麼? –

回答

0

這就是RelativeLayouts在這裏扮演很重要的角色,因爲您可以將視角置於另一個視角之上,並將焦點置於頂部,反之亦然。所以,首先你編譯Android的最新支持設計庫到本地的build.gradle文件來使用FAB,然後做這樣的事情的佈局文件:

<?xml version="1.0" encoding="utf-8"?> 
<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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    tools:context="com.davenotdavid.stackoverflow.MainActivity"> 

    <EditText 
     android:id="@+id/et1" 
     android:hint="HINT..." 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

    <EditText 
     android:id="@+id/et2" 
     android:hint="HINT..." 
     android:layout_below="@id/et1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

    <EditText 
     android:id="@+id/et3" 
     android:hint="HINT..." 
     android:layout_below="@id/et2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" /> 

</RelativeLayout> 

...然後如果FAB也許測試已經集中在聚焦的EditText通過顯示吐司消息在您的onCreate(相對於EditText上的鍵盤彈出)()如下:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Toast.makeText(MainActivity.this, "FAB clicked", Toast.LENGTH_SHORT).show(); 
     } 
    }); 
} 
+1

謝謝!你指出我需要的方向:) –

相關問題