标签: android-styles

示例和说明:Android(Studio)登录活动模板生成的活动

我想在我的应用程序中实现一个登录表单,所以我尝试使用Android Studio向导生成的代码来创建一个类型为Login Form的新Activity.我认为Eclipse生成的代码几乎是一样的.

不幸的是,生成的代码没有提供预期的结果:我创建了一个很好的简单登录表单,但是如果密码正确或错误,它不会从登录表单移动.

我还注意到没有创建"注册"表单.

看了一下,然后分析代码,我终于搞定了:)

请参阅下面的回复.

android login android-styles

21
推荐指数
1
解决办法
5万
查看次数

如何将getsStyledAttributes(int [])与Android的内部主题一起使用

所以我环顾四周,发现它android.R.styleable不再是SDK的一部分,即使它仍然在这里记录.

如果清楚地记录了备选方案的内容,那就不会成为问题.例如,AOSP日历应用程序仍在使用android.R.styleable

// Get the dim amount from the theme   
TypedArray a = obtainStyledAttributes(com.android.internal.R.styleable.Theme);
lp.dimAmount = a.getFloat(android.R.styleable.Theme_backgroundDimAmount, 0.5f);
a.recycle();
Run Code Online (Sandbox Code Playgroud)

那么如果backgroundDimAmount没有得到它int[],怎么会得到android.R.styleable.Theme

obtainStyledAttributes(int [])为了使其与SDK一起使用,我需要注意什么?

android android-xml android-resources android-styles

19
推荐指数
4
解决办法
4万
查看次数

没有设置Android主题

我有一个拒绝应用于活动的主题 - 没有应用任何样式.如果我没有为它提供layout_width/ layout_height属性<Button>也会收到运行时错误,表明Button该类没有被应用.

/res/values/themes.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Theme" parent="android:style/Theme.Black">
        <item name="android:windowNoTitle">true</item>
        <item name="android:buttonStyle">@style/Button</item>
        <item name="android:windowBackground">@color/page_background_light</item>
        <item name="android:textAppearance">@style/TextAppearance</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

/res/values/styles.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="TextAppearance" parent="@android:style/TextAppearance">
        <item name="android:textSize">12sp</item>
        <item name="android:textColor">@color/darkblue</item>
    </style>
    <style name="Button" parent="@android:style/Widget.Button">
        <item name="android:layout_width">fill_parent</item> 
        <item name="android:layout_height">wrap_content</item>
        <!--<item name="android:textColor">#3C2F4F</item>
        <item name="android:textSize">20dip</item>-->
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

和相关的清单设置:

<application android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@style/Theme">
Run Code Online (Sandbox Code Playgroud)

我错过了哪个明显的错误?

android themes android-manifest android-styles

19
推荐指数
2
解决办法
2万
查看次数

自定义SearchView整个可在android中点击

我的应用程序中有一个SearchView小部件,我想问一些关于使它自定义的问题.首先,您只能通过点击搜索图标开始搜索,有没有办法让整个SearchView可点击?此外,还有一种方法可以在单击时使SearchView显示为这样吗?

一只忙碌的猫http://i41.tinypic.com/rr2ow4.png ![] [1]

它现在处于这种状态:

一只忙碌的猫http://i41.tinypic.com/11jlu2p.png ![] [1]

这是我的代码:

citySearch = (SearchView) findViewById(R.id.city_search_bar);
citySearch.setBackgroundResource(R.drawable.search_background);
citySearch.setOnSearchClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {
        citySearch.setIconifiedByDefault(true);
        //citySearch.setIconified(true);
    }

});
citySearch.setOnQueryTextListener(new OnQueryTextListener() {

    @Override
    public boolean onQueryTextChange(String text) {

        ((Filterable) cityListView.getAdapter()).getFilter().filter(text);

        return false;
    }

    @Override
    public boolean onQueryTextSubmit(String text) {

        return false;
    }

});

try
{
    Field searchField = SearchView.class.getDeclaredField("mSearchButton");
    searchField.setAccessible(true);
    ImageView searchBtn = (ImageView)searchField.get(citySearch);
    searchBtn.setImageResource(R.drawable.search_icon);
    searchBtn.setScaleType(ScaleType.FIT_CENTER);
    searchPlate.setBackgroundResource(R.drawable.search_background);
}
catch (NoSuchFieldException e)
{
    Log.e("SEARCHSTYLEERROR",e.getMessage(),e);
}
catch (IllegalAccessException e)
{
    Log.e("SEARCHSTYLEERROR",e.getMessage(),e);
}
Run Code Online (Sandbox Code Playgroud)

android searchview android-search android-styles

18
推荐指数
2
解决办法
7515
查看次数

EditText如何在没有任何操作栏的情况下激活复制/粘贴弹出窗口?

我在delphi下,我使用android框架创建一个编辑.当我将主题设置为Theme.DeviceDefault.Light.NoActionBar然后我可以在我的EditText中选择一些文本,我有一个弹出窗口"select all/cut/copy/paste/etc",如下图所示.

但是,当我选择Theme.Material.Light.NoActionBarTheme.Holo.Light.NoActionBar然后我无法选择我的EditText中的任何文本(我没有右或左文本选择句柄),当然我没有任何复制/粘贴弹出窗口

他们是否可以在Theme_Material_Light_NoActionBar上进行此复制/粘贴弹出?

在此输入图像描述 Theme.DeviceDefault.Light.NoActionBar

在此输入图像描述 Theme_Material_Light_NoActionBar

在此输入图像描述 Theme.Holo.Light.NoActionBar

注1:

当我将屏幕移动到水平然后编辑文本占用所有可用空间,然后我可以看到我的左右文本选择句柄,如下图所示,但我认为这是因为主题交换到Theme.DeviceDefault.Light.NoActionBar当我将屏幕移动到水平但我不确定:

在此输入图像描述

注2:

在我的editText上,当我执行setCustomSelectionActionModeCallback(new Callback(){})时,从不调用Callback :(这是不正常的我认为?editText中的哪些内容可以禁止回调?

注2:

我可以在所有主题中选择文本(但我不能将其复制出去),但除了在Theme.DeviceDefault.Light.NoActionBar中,我看不到左右文本选择句柄.

注3:

Theme.DeviceDefault.Light.NoActionBar仅在某些手机上显示左右文本选择句柄,如三星星系.在其他方面它没有用.

注4:

我发现了部分问题的根源!这是因为我通过WindowManager.addView(view,layout_params)创建我的视图,这样startactionmodeforChild返回null,这禁止动作栏和文本选择句柄显示.现在如果我在我的edittext中做了类似的事情:

@Override
public ActionMode startActionMode(ActionMode.Callback callback) {
    Activity host = (Activity) this.getContext();    
    return host.getWindow().getDecorView().startActionMode(callback); 
} 
Run Code Online (Sandbox Code Playgroud)

然后我可以看到左右文本动作句柄(但不是棉花糖,它只在棒棒糖上工作,我不知道为什么).我现在的问题是显示了操作栏,但它显示为空:(内部没有任何内容(但我可以看到剪切/复制/过去控件位于转储视图中的内部).所以现在我不寻找方法通过弹出菜单替换此操作栏(如图片Theme.DeviceDefault.Light.NoActionBar).任何想法?

android textview android-theme android-edittext android-styles

18
推荐指数
2
解决办法
5434
查看次数

如何设置ActionBar样式,选中选项卡上的选项卡背景

我正在努力设计ActionBar.我的应用程序有一个带有三个选项卡的ActionBar.我试图让选定的标签具有背景颜色,而未选择的标签显示不同的颜色.我正在关注此参考:自定义操作栏.但是所有TAB都显示了选定的颜色.

我的styles.xml文件如下:

<style name="MyActionBarTabStyle" parent="android:style/Widget.Holo.Light.ActionBar.TabBar">
    <item name="android:background">@drawable/tab_background</item>
    <item name="android:paddingLeft">32dp</item>
    <item name="android:paddingRight">32dp</item>
</style> 

<style name="MyActionBarTabBarStyle" parent="android:style/Widget.Holo.Light.ActionBar.TabBar">

    <item name="android:background">@drawable/red</item>
</style> 


<style name="AppTheme.Light" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/ActionBar.Light</item>
    <item name="android:actionBarTabStyle">@style/MyActionBarTabStyle</item>
    <item name="android:actionBarTabBarStyle">@style/MyActionBarTabBarStyle</item>

</style>
Run Code Online (Sandbox Code Playgroud)

tab_background只是一个9补丁.我也不确定我是否从正确的parent(parent="android:style/Widget.Holo.Light.ActionBar.TabBar)继承了操作栏选项卡.我查看了参考资料,发现很难理解样式层次结构

为什么我的标签显示不选择?提前感谢你的帮助.

android android-actionbar android-tabs android-styles

17
推荐指数
1
解决办法
2万
查看次数

如何在Android中为按钮设置样式?

我在res文件夹中定义了以下文件.

styles_apptheme.xml

<?xml version="1.0" encoding="utf-8"?>

<!-- Generated with http://android-holo-colors.com -->
<resources xmlns:android="http://schemas.android.com/apk/res/android">

  <style name="ButtonAppTheme" parent="android:Widget.Holo.Light.Button">
      <item name="android:background">@drawable/apptheme_btn_default_holo_light</item>
  </style> 
</resources>
Run Code Online (Sandbox Code Playgroud)

themes_apptheme.xml

<?xml version="1.0" encoding="utf-8"?>

<!-- Generated with http://android-holo-colors.com -->
<resources xmlns:android="http://schemas.android.com/apk/res/android">

  <style name="AppTheme" parent="@style/_AppTheme"/>

  <style name="_AppTheme" parent="Theme.AppCompat.Light">

    <item name="android:editTextBackground">@drawable/apptheme_edit_text_holo_light</item>

    <item name="android:buttonStyle">@style/ButtonAppTheme</item>

  </style>

</resources>
Run Code Online (Sandbox Code Playgroud)

在我的Layout.xml文件中,我已经定义了我的按钮,如下所示

<Button
        android:id="@+id/btnAddTitle"
        android:layout_below="@id/edEnterTitleValue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/btn_AddTitle"
        android:layout_margin="20dp"
/>
Run Code Online (Sandbox Code Playgroud)

如果我将以下行添加到上面的按钮视图,

android:background="@style/ButtonAppTheme"
Run Code Online (Sandbox Code Playgroud)

应用程序崩溃说应该为background属性设置drawable资源.

所以我创建了下面的drawable文件 - abc.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_window_focused="false" android:state_enabled="true"
        android:drawable="@drawable/apptheme_btn_default_normal_holo_light" />
    <item android:state_window_focused="false" android:state_enabled="false"
        android:drawable="@drawable/apptheme_btn_default_disabled_holo_light" />
    <item android:state_pressed="true"
        android:drawable="@drawable/apptheme_btn_default_pressed_holo_light" />
    <item android:state_focused="true" android:state_enabled="true"
        android:drawable="@drawable/apptheme_btn_default_focused_holo_light" />
    <item android:state_enabled="true" …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-button android-styles

17
推荐指数
3
解决办法
9万
查看次数

Android:如何在styles.xml中自定义声明XML命名空间?

我正在尝试将自定义XML命名空间放入其中styles.xml并在布局中继承它.我不知道如何styles.xml在布局xml(例如xmlns:app="http://schemas.android.com/tools")中声明自定义XML命名空间.

我如何在styles.xml?中使用自定义XML命名空间?

是)我有的:

  1. 字体资产,ReallyCoolFont.ttf保存在asset/fonts.

  2. my_layout.xml:

    <TextView
        <!-- more attributes here -->
        app:customFont="fonts/ReallyCoolFont.ttf" 
        <!-- more attributes here -->
    </TextView>
    
    Run Code Online (Sandbox Code Playgroud)
  3. styles.xml:

    <style name="CoolTextView">
        <!-- more items here -->
        <!-- more items here -->
    </style>
    
    Run Code Online (Sandbox Code Playgroud)

我想要的是:

  1. my_layout.xml:

    <TextView
        <!-- more attributes here -->
        style="@style/CoolTextView
        <!-- more attributes here -->
    </TextView>
    
    Run Code Online (Sandbox Code Playgroud)
  2. styles.xml:

    <style name="CoolTextView">
        <!-- more items here -->
        <item name="app:customFont">ReallyCoolFont.ttf</item>
        <!-- more items here -->
    </style>
    
    Run Code Online (Sandbox Code Playgroud)

我得到的错误: …

xml layout android android-layout android-styles

17
推荐指数
5
解决办法
8379
查看次数

覆盖Action Bar不起作用

我正在关注覆盖行动栏的官方开发人员指南.

style.xml的如下:

<!-- Base application theme. -->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
</style>

<style name="AppTheme" parent="AppBaseTheme">
    <item name="actionBarStyle">@style/CustomActionBarTheme</item>

</style>

<style name="CustomActionBarTheme"
    parent="@android:style/Theme.Holo">
    <item name="android:windowActionBarOverlay">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我的midSdkVersion是14,预期输出与官方指南相似:在此输入图像描述.

相反,在我的情况下,输出是: 在此输入图像描述

(我已将背景颜色设置为活动...但它不会覆盖操作栏.)

如果我做的任何事都错了,请帮助我.

编辑:

我想在airnb和许多其他应用程序中使用类似的动作栏.任何人都可以给我完整的答案吗?

在此输入图像描述

android android-layout android-actionbar android-styles

16
推荐指数
1
解决办法
3万
查看次数

Android固定大小对话框维度 - 什么是主要和次要?

这些属性代表什么?主要维度和次要维度之间的差异?

<style name="Theme.Base.AppCompat.Dialog.FixedSize" parent="android:Theme.Dialog">
    <item name="windowFixedWidthMajor">@dimen/dialog_fixed_width_major</item>
    <item name="windowFixedWidthMinor">@dimen/dialog_fixed_width_minor</item>
    <item name="windowFixedHeightMajor">@dimen/dialog_fixed_height_major</item>
    <item name="windowFixedHeightMinor">@dimen/dialog_fixed_height_minor</item>
.......
</style>
Run Code Online (Sandbox Code Playgroud)

android android-styles

16
推荐指数
1
解决办法
2960
查看次数