使用Android SDK,似乎没有任何方法可以在表格行上设置样式.我想做相同的:
<TableRow
style='@style/TableRow_classic' >
Run Code Online (Sandbox Code Playgroud)
在代码中.我想要像:
TableRow row = new TableRow(this);
row.setStyle(R.style.TableRow_classic);
Run Code Online (Sandbox Code Playgroud)
有谁知道如何找到这个?
我一直试图Views在整个应用程序中找到奇怪的格式化样式不一致的原因,我想我已经用这个例子缩小了它.
我Views使用完全相同的过程设置了两个等效的各种s 布局,并且只改变了Context创建中提供的内容.在第一个集合中,每个View都是通过应用程序的上下文创建的Activity.getApplicationContext(),而在第二个集合中,Views是通过活动的上下文this.
结果大不相同:

有关使用应用程序上下文的原因的任何建议都会导致屏幕截图中出现垃圾(并且不一致 - 颜色为白色和灰色)?
活动代码:
import android.os.Bundle;
import android.app.Activity;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// TextViews
TextView tv1 = new TextView(getApplicationContext());
tv1.setText("With Application context");
TextView tv2 = new TextView(this);
tv2.setText("With Activity context");
// Spinners
Spinner sp1 = new Spinner(getApplicationContext());
sp1.setAdapter(new ArrayAdapter<String>(getApplicationContext(), …Run Code Online (Sandbox Code Playgroud) 我在列表视图中显示的复选框中存在样式问题.我的应用使用的主题是Holo,但复选框以旧样式显示.出现在别处的复选框看起来很好.我没有做任何花哨的事情,比如创造我自己的风格.截图:

复选框应该看起来像右图上的复选框.这是在v4.0.3上.复选框看起来应该在我尝试使用v4.4.2的其他设备上.
列表视图行的XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<CheckBox android:id="@+id/ListRow_Task_TaskComplete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="6sp"
android:focusable="false" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="7dip"
android:paddingBottom="7dip"
android:layout_toRightOf="@+id/ListRow_Task_TaskComplete"
android:layout_centerVertical="true" >
<TextView android:id="@+id/ListRow_Task_Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp" />
// next two textviews are programmatically hidden right now
<TextView android:id="@+id/ListRow_Task_Deadline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="12sp" />
<TextView android:id="@+id/ListRow_Task_Tags"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/icon_tag"
android:drawablePadding="4dip"
android:textSize="12sp" />
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
如何使左侧的复选框看起来像它们应该的那样?
你能帮我搞清楚为什么我的警报对话框黑了?!
最近我更改了我的应用主题以支持材料设计,但我的警报对话框变黑了!
这是我的创建对话框代码:
AlertDialog.Builder alertDialog = new AlertDialog.Builder(TestActivity.this);
alertDialog.setCancelable(true);
alertDialog.setTitle("sample");
alertDialog.setItems(new String[] { "a", "b" }, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
alertDialog.show();
Run Code Online (Sandbox Code Playgroud)
它是我的主要风格和对话风格
<style name="MaterialTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:alertDialogStyle">@style/AppDialog</item>
<item name="android:alertDialogTheme">@style/AppDialog</item>
<item name="android:textColor">@color/black</item>
<item name="android:textColorPrimary">@color/black</item>
<item name="android:dialogTheme">@style/AppDialog</item>
<item name="colorPrimaryDark">@color/myPrimaryDarkColor</item>
<item name="android:textColorHint">@color/gray_1</item>
<item name="colorAccent">@color/myAccentColor</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="android:windowBackground">@color/black</item>
</style>
<style name="AppDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">#FFC107</item>
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="android:background">#4CAF50</item>
</style>
Run Code Online (Sandbox Code Playgroud) 我正在使用新工具栏并将其设置为supportActionBar.我的问题是它覆盖了我的内容.
这是我用来设置工具栏的代码.
public void setupNavBar() {
mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
if (mToolbar != null) {
setSupportActionBar(mToolbar);
mActionBar = getSupportActionBar();
mActionBar.setDisplayShowHomeEnabled(true);
mActionBar.setDisplayShowTitleEnabled(false);
}
}
Run Code Online (Sandbox Code Playgroud)
风格:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
<style name="ToolBarStyle" parent="">
<item name="android:elevation">5dp</item>
<item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
<item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>
Run Code Online (Sandbox Code Playgroud)
和布局:
<RelativeLayout 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"
tools:context=".MainActivity">
<android.support.v7.widget.Toolbar
style="@style/ToolBarStyle"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/material_blue_grey_800"
android:minHeight="@dimen/abc_action_bar_default_height_material"
android:id="@+id/toolbar_actionbar"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#478"
android:text="@string/hello_world" />
Run Code Online (Sandbox Code Playgroud)
我认为通过调用setSupportActionbar,系统将负责在工具栏视图下方定位内容,但这不是我所看到的.
使用工具栏的正确方法是什么.我有一些活动,我希望工具栏透明,背后的内容和其他我希望它与下面的内容不透明.
谢谢
这是我的应用主题:
<style name="BaseTheme" parent="Theme.AppCompat.Light">
...
<item name="colorControlActivated">@color/default_orange</item>
...
</style>
...
<style name="Switch" parent="Material.Widget.Switch">
<item name="colorControlActivated">@color/default_green</item>
</style>
Run Code Online (Sandbox Code Playgroud)
如果我使用Switch风格:
<com.rey.material.widget.Switch
style="@style/Switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"/>
Run Code Online (Sandbox Code Playgroud)
在colorControlActivated使用它的里面的一个BaseTheme(橙色),而不是开关一个(绿色).
为什么会这样?colorControlActivated对于不同的观点我不能有不同的看法吗?
谢谢.
android android-appcompat android-styles android-5.0-lollipop
使用我的应用主题,我使用此属性显示彩色导航栏(屏幕底部带有后退按钮的导航栏)
<item name="android:navigationBarColor">@color/theme_color</item>
Run Code Online (Sandbox Code Playgroud)
当软键盘出现时,颜色变为黑色.我想保留我的主题颜色.
android soft-keyboard navigationbar android-theme android-styles
我试图禁用我的一些活动的操作栏,但无论我尝试什么,我似乎无法删除它.
在我的styles.xml中,我有:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
Run Code Online (Sandbox Code Playgroud)
在我的manifest.xml中,我有:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".NewActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
</activity>
</application>
Run Code Online (Sandbox Code Playgroud)
我的活动布局文件:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_new"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
我的app_bar_new布局文件:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" …Run Code Online (Sandbox Code Playgroud) API级别21或更高级别的状态栏颜色根据我的要求而变化,但是如何更改API级别21以下的颜色。
以下是两个API的屏幕截图
API级别21:

API等级19:

colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FFFFFF</color>
<item name="b" type="color">#FF33B5E5</item>
<item name="p" type="color">#FFAA66CC</item>
<item name="g" type="color">#FF99CC00</item>
<item name="o" type="color">#FFFFBB33</item>
</resources>
Run Code Online (Sandbox Code Playgroud)
Style.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowActionBarOverlay">false</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
<item name="tabSelectedTextColor">@color/colorAccent</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> …Run Code Online (Sandbox Code Playgroud) 我的标签TabLayout占据了屏幕的中心,即使tabMaxWidth = "0dp"按照Adam John的回答添加,也没有填满整个宽度
这是我希望通过制表符扩展到填充屏幕,如下所示:
但我得到的是:
我的XML看起来像这样:
<android.support.design.widget.TabLayout
android:id="@+id/tl_contact_type"
style="@style/tabWidgetLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMaxWidth="0dp"
app:tabGravity="fill"
app:tabMode="fixed"/>
Run Code Online (Sandbox Code Playgroud)
style.xml for tabWidgetLayout
<style name="tabWidgetLayout" parent="Widget.Design.TabLayout">
<item name="tabIndicatorColor">@color/colorTealAccent</item>
<item name="tabIndicatorHeight">@dimen/default_corner_radius_medium</item>
<item name="tabBackground">?attr/selectableItemBackground</item>
<item name="android:background">@color/colorBrandPrimaryDark</item>
<item name="tabSelectedTextColor">@color/color_tab_selected_text</item>
<item name="tabTextAppearance">@style/tabWidgetLayoutTextAppearance</item>
</style>
Run Code Online (Sandbox Code Playgroud)
任何帮助解决这个问题非常感谢.