私はこのボタンを使って、この最小のAndroid Studioプロジェクトを持っています。 私はボタンを影を割り当てる:Android APIのボタンの高さ(シャドー)を21未満にエミュレートするにはどうすればよいですか?
android:elevation="3dp"
android:translationZ="3dp"
android:stateListAnimator="@null"
と私は、Android Studioの[デザイン]タブに影を参照してください。しかし、私はまた、唯一のAPIレベル21以降で使用されているXMLエディタ
Atribute ...で警告を受ける
(現在の分は16である)そして実際、ボタンの影が表示されますAPI level 21 or higher
のエミュレータでのみ表示され、フラットに表示され、エミュレータには影が全くありません。API level lower than 21
です。
具体的な質問は、API's lower than 21
でシャドウエフェクトをエミュレートする方法です。
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:id="@+id/main_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="1">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:layout_weight="2.24">
<Button
android:id="@+id/my_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="20dp"
android:layout_marginBottom="20dp"
android:elevation="5dp"
android:translationZ="5dp"
android:stateListAnimator="@null"
android:background="@android:color/holo_green_light"
android:text="BUTTON"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
@Ramiroあなたはそれを取得したりしませんでした? – Ironman
はい@アイロンマン、それは動作します。しかし、それはボタンの押された、focustedなどを扱う多くの仕事を必要とするので、私はボタンの外観を各APIのGoogleが意図していたままにしておきます。ありがとう! – Ramiro