我知道这可以通过使用相对布局很容易地完成,但我觉得我正在做的是正确的,并且应该使用线性布局本身给我想要的结果.但出于某种原因,当我在运行Android JB 4.1.2的Google Nexus 7上运行时,我会在列表视图项之后立即看到按钮和文本视图.如果列表视图为空,我会在屏幕顶部看到它们.难道我做错了什么??这是我的xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/attachments_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1"
android:orientation="vertical">
<ListView
android:id="@+id/mtg_attachments"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="@+id/attach_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/delete"
android:textSize="22sp" />
<TextView
android:text="@string/attach_warning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我是Android开发的新手,我想知道是否有任何样本可用于创建类似于Android上google + app底部的photo/checkin/mood/write面板的面板.
1)它们是4个按钮吗?如何设置按钮的样式?
2)我想在向下滚动时自动隐藏面板,但在向上滚动时显示.
感谢是否有人可以指导我正确的方向.
干杯

我有一个按钮
Button button = (Button)findViewById(R.id.button);
button.setBakgroundResource(R.drawable.icon);
Run Code Online (Sandbox Code Playgroud)
如果我想检查哪个背景资源按钮有,是否可以这样做?如何。
例如 :
if (button.getResourceId()==R.drawable.icon)
Run Code Online (Sandbox Code Playgroud)
做点什么...
更新:条件为假我希望它是真实的图像不匹配
vi.findViewById(R.id.button1).setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
v.findViewById(R.id.button1).setBackgroundResource(R.drawable.boutton_off);
Drawable aImg = (Drawable)v.findViewById(R.id.button1).getBackground();
Drawable bImg = v.getResources().getDrawable(R.drawable.boutton_off);
if(aImg==bImg){
System.out.println("On");
}else
System.out.println("off");
//main.popMessage(position);
}
});
Run Code Online (Sandbox Code Playgroud) 我正在尝试将我的操作按钮的形状从这个默认形状更改为矩形。这是我的 xml:
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:cornerRadius="90dp"
android:text="@string/create_player_text"
android:fontFamily="@font/proximanova_semibold"
app:layout_constraintHorizontal_bias="0.99"
app:layout_constraintVertical_bias="0.01"/>
Run Code Online (Sandbox Code Playgroud)
android android-layout android-button floating-action-button material-components-android
我正在尝试更改按钮的背景颜色。我在模拟器上使用 SDK 21 的 Kotlin。
View 和 Button 在布局 XML 文件中声明
<View
android:id="@+id/myview"
android:layout_width="64dp"
android:layout_height="32dp"
/>
<Button
android:id="@+id/showButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="12dp"
android:text="test"
/>
Run Code Online (Sandbox Code Playgroud)
设置颜色的 API 似乎不起作用:
showButton.setBackgroundColor(0xff60a0e0.toInt()) <-- doesnt work
Run Code Online (Sandbox Code Playgroud)
有效的是:
myview.setBackgroundColor(0xff60a0e0.toInt()) <-- works, exact background color
showButton.setTextColor(0xff000050.toInt()) <-- works, exact text color
Run Code Online (Sandbox Code Playgroud)
经过进一步尝试后,我似乎只能设置按钮的 Alpha 通道,而不能设置颜色:
setBackgroundColor( 0xff000000.toInt()) <-- works, opaque
setBackgroundColor( 0x00000000.toInt()) <-- works, transparent
Run Code Online (Sandbox Code Playgroud)
同样的事情还有:
showButton.setBackgroundColor(Color.GREEN) <-- doesnt work, button is opaque but not green
showButton.setBackgroundColor(Color.TRANSPARENT) <-- works, button is transparent
Run Code Online (Sandbox Code Playgroud)
任何想法?我是否错过了其他答案或文档中的某些内容?
这是完整的布局,它用于填充片段(如果重要的话):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" …Run Code Online (Sandbox Code Playgroud) android android-button kotlin material-components material-components-android
我正在使用最新的材料组件 - 1.1.0-beta01。
当 ExtendedFloatingActionButton 展开时,其高度也会降低。
以下是 xml 布局的外观:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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/main_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="56dp"
android:text="Text"
android:textColor="#02220D"
android:backgroundTint="#F2C203"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:textSize="15sp"
android:fontFamily="sans-serif-medium"
android:textStyle="normal"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:iconTint="#02220D"
app:icon="@drawable/ic_camera"
app:iconPadding="10dp"
android:insetLeft="0dp"
android:insetBottom="0dp"
android:insetTop="0dp"
android:insetRight="0dp"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
我试图设置最小和最大高度,但没有用。知道如何在按钮展开和收缩时达到相同的高度吗?
谢谢。
android android-button floating-action-button material-components material-components-android
我想定义一个替代的按钮样式,它使用我的 secondaryColor 作为背景,并?colorOnSecondary分别用于文本。
但是我很难在样式中定义 textColor 。MaterialButton 正在为使用?colorOnPrimary. 因此,重写很麻烦。
有没有另一种方法可以在没有 selectorDrawable 的情况下设置颜色?
android android-button material-components material-components-android
<com.google.android.material.button.MaterialButton
android:id="@+id/button_tour"
app:cornerRadius="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="30dp"
android:layout_gravity="center_horizontal"
android:text="Take a tour"/>
Run Code Online (Sandbox Code Playgroud)
我在我的android项目中添加了一个材质按钮,当我尝试使用 设置圆角时app:cornerRadius,我发现它根本不起作用。
android android-button material-design material-components material-components-android
当我打开一个新的 android studio 项目时,按钮的默认颜色是紫色。我希望默认颜色是灰色的默认按钮颜色(我假设你知道我的意思)。我试图通过 xml 和 java 更改颜色,但没有任何效果。我希望默认按钮颜色为灰色,而不必每次都更改它。

他们的.xml:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.HangmanGame" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
Run Code Online (Sandbox Code Playgroud)
主题.xml(晚上)
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.HangmanGame" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/black</item>
<!-- Secondary …Run Code Online (Sandbox Code Playgroud) android ×10
android-button ×10
material-components-android ×6
java ×2
button ×1
kotlin ×1
xml ×1