无法将 MaterialToggleButton 的选定颜色设置为纯色,仅显示原色的透明阴影。
我尝试了下面的代码集,输出图像如下所示。
样式中的按钮主题
<style name="ThemeButtonColorToggle" parent="AppTheme">
<item name="colorPrimary">@color/colorOrange</item>
<item name="colorButtonNormal">@color/colorOrange</item>
<item name="android:backgroundTint">@color/black</item>
<item name="strokeColor">@color/colorOrange</item>
<item name="strokeWidth">@dimen/mtrl_btn_stroke_size</item>
<item name="colorOnPrimary">@color/colorOrange</item>
<item name="colorOnPrimarySurface">@color/colorOrange</item>
</style>
Run Code Online (Sandbox Code Playgroud)
XML代码
<com.google.android.material.button.MaterialButtonToggleGroup
android:id="@+id/toggleGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:checkedButton="@id/btnAndroid"
app:layout_constraintTop_toBottomOf="@id/tvName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:selectionRequired="true"
app:singleSelection="true">
<com.google.android.material.button.MaterialButton
android:id="@+id/btnAndroid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:theme="@style/ThemeButtonColorToggle"
android:textColor="@android:color/white"
android:textColorHighlight="@color/colorOrange"
android:text="Android" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btniOS"
android:layout_width="wrap_content"
android:textIsSelectable="true"
android:textColor="@android:color/white"
android:theme="@style/ThemeButtonColorToggle"
android:layout_height="wrap_content"
android:text="iOS" />
</com.google.android.material.button.MaterialButtonToggleGroup>
Run Code Online (Sandbox Code Playgroud)
我需要得到如下所示的纯色
谁能帮我解决一下
android android-button android-togglebutton material-components-android
有没有办法以编程方式将单选按钮的文本与顶部对齐,如下所示。
我使用以下代码创建无线电组
final RadioButton[] rb = new RadioButton[5];
RadioGroup rg = new RadioGroup(getActivity()); //create the RadioGroup
rg.setOrientation(RadioGroup.VERTICAL);//or RadioGroup.VERTICAL
rg.setLayoutParams(radioparams);
for (int i = 0; i < 5; i++) {
rb[i] = new RadioButton(getActivity());
rb[i].setText("Radiobtn " + i);
rb[i].setId(i + 100);
rg.addView(rb[i]);
}
layout.addView(rg);
Run Code Online (Sandbox Code Playgroud)
但我将文本放在每个按钮的右侧。
我有一个片段布局,我想动态添加另一个子布局,
子布局xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:hint="Question"
android:textColor="@color/colorTextBlack"
android:textSize="16dp" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
这是我的主要布局
<?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:background="#f2f2f2"
android:orientation="vertical">
<FrameLayout
android:id="@+id/flContainer"
android:layout_width="match_parent"
android:layout_margin="20dp"
android:layout_height="wrap_content"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
在我的片段中我包含了子布局
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_start_question, container, false);
flContainer = (FrameLayout) v.findViewById(R.id.flContainer);
flContainer.addView(R.layout.sub_layout);
return v;
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助找到错误
我的strings.xml中有一个字符串,它们之间有"\n"符号
<string name="example">Hello\nworld</string>
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能得到"\n"符号而不是新行?
在布局中显示此类型的选项卡
我尝试了但没有得到正确的输出
我的代码在这里
private int[] imageList= {R.drawable.icon_category,R.drawable.icon_newest};
tabLayout=(TabLayout)findViewById(R.id.tabs);
tabLayout.addTab(tabLayout.newTab().setText(""));
tabLayout.addTab(tabLayout.newTab().setText(""));
for (int i = 0; i < imageList.length; i++) {
tabLayout.getTabAt(i).setIcon(imageList[i]);
}
Run Code Online (Sandbox Code Playgroud) android ×5
android-tabs ×1
fragment ×1
include ×1
material-components-android ×1
radio-button ×1
radio-group ×1
string.xml ×1