我对材料设计的按钮样式感到困惑.我想得到彩色凸起的按钮,如附带的链接,就像在使用部分下看到的"强制停止"和"卸载"按钮一样.是否有可用的样式或我需要定义它们?
http://www.google.com/design/spec/components/buttons.html#buttons-usage
我找不到默认的按钮样式.
例:
<Button style="@style/PrimaryButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculate"
android:id="@+id/button3"
android:layout_below="@+id/editText5"
android:layout_alignEnd="@+id/editText5"
android:enabled="true" />
Run Code Online (Sandbox Code Playgroud)
如果我尝试通过添加更改按钮的背景颜色
android:background="@color/primary"
Run Code Online (Sandbox Code Playgroud)
所有的风格都消失了,比如触摸动画,阴影,圆角等.
在我的Android应用中,我有这样的布局:
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
class="com.google.android.gms.maps.SupportMapFragment"/>
<Button
android:id="@+id/button_back"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="CloseActivity"
android:padding="0dp"
android:text="@+string/back" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
在预览和手机上,它看起来像:

正如你在底部区域的按钮上看到的那样,那里有一些填充物.
我怎样才能摆脱它,让按钮完全填满底部区域?
我有以下布局文件:
activity_main.xml中
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/frame_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="0px"
android:layout_marginRight="0px"
android:layout_marginTop="0px"
android:padding="0dp"
>
...
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
和其他一些片段一样
fragment_init.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragmentInit"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="0dp"
android:layout_marginTop="0px"
android:layout_marginLeft="0px"
android:layout_marginRight="0px"
android:background="#549F07"
>
<TextView
...
>
...
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
Lint中的一切看起来都很好,但是当我在Nexus 7 5.0.2上执行我的应用程序时,每个容器都会显示一个填充或边距可能为10像素.
如何强制布局不添加这些填充/边距?
编辑:我应该添加我插入片段的方式.
Activiy
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
fragmentTransaction.replace(R.id.frame_container, new Fragment_init(), "Fragment_init").commit();
}
}
Run Code Online (Sandbox Code Playgroud)
而且我在任何地方都不使用任何尺寸... Thks
我正在尝试创建一个按钮,该按钮连接到按钮上方的TextView,如下图所示.
上面的截图来自Note 4,操作系统版本是5.0.1.
下面是用于实现UI的代码.
布局/ xyz.xml
<Button
android:layout_width="250dp"
android:layout_height="50dp"
android:theme="@style/myButton"
android:text="Cancel"/>
Run Code Online (Sandbox Code Playgroud)
值-V21/style.xml
<style name="myButton" parent="@style/Base.Widget.AppCompat.Button">
<item name="android:colorButtonNormal">#3578A9</item>
<item name="android:inset">0dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但是如果我在Nexus4 OS verison 5.1.1中运行相同的代码,则该按钮会占用所有4个边的边距,屏幕截图如下所示.
如果我删除"android:theme"并提供"android:background",则UI看起来像第一个图像.但它不会产生连锁反应.那么如何通过涟漪效应实现UI作为第一个图像.