Android - how to disable / change editTexts 'Pin' - java

How can I edit or disable the 'pin' for editTexts that appears when marking text? I was able to edit the underline & the cursor, but not that 'pin' because I didn't know how to call it.
Image of the pin (pink) added.

I think the colourAccent influences the colour of that pin, try changing the colour of colourAccent in color.xml

This 'pin' is called "text select handle"
To change it you need to use these attributes:
text_select_handle_left and text_select_handle_right

Add these drawables with customized design/color to your drawable folder and add to style
<style name="MyTheme" parent="#style/MyCustomTheme">
<item name="android:textSelectHandle">#drawable/text_select_handle_middle</item>
<item name="android:textSelectHandleLeft">#drawable/text_select_handle_left</item>
<item name="android:textSelectHandleRight">#drawable/text_select_handle_right</item>
</style>

Related

Adding components programmatically has different style than those in XML layout

Components (text and edit boxes) defined in layout XML looks very different from those i add programatically.
I've tried to apply the same textAppearance style programatically as the ones from my XML has. I tried calling setTheme() after adding the components too. No difference.
TextView tv10 = new TextView(getApplicationContext());
tv10.setText("Back width");
EditText tv11 = new EditText(getApplicationContext());
tv11.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_CLASS_NUMBER);
TextView comes out with small font and gray text, EditText comes out with black background and gray text.
The components must be added programmatically because of options the user choose. Those user choices are defined in the XML and follow the expected color scheme, which is the Android Studio defaults. (Black text on white background)
You shouldn't use Application Context for views. Only Activity context. Also you can pass style as parameter, when create view in code.
As Yamko said, style can be passed in the constuctor
var textView = TextView(context, null, R.style.LoginBodyTextViewStyle)
where the style can be something like
<style name="LoginBodyTextViewStyle" parent="android:Widget.TextView">
<item name="android:textStyle">normal</item>
<item name="android:fontFamily">sans-serif</item>
<item name="android:textSize">#dimen/text_size_default</item>
<item name="android:textColor">#color/grey</item>
</style>

Can I change my android application style at runtime?

I want to change the manifest style when the user chooses a setting in the preferences file or settings. I have a setting in my apk which includes a list of preferences with three entries {Style_1, Style_2, Style_3}. I want to change the style color, like primaryColor, when the user clicks a style. How can I do this?
Yes you can do this easily, I do it all the time.
Just call this method before setContentView like this:
setTheme(R.style.Theme);
setContentView(R.layout.activity_layout);
Now what I do is that i take a static int variable in the app constants and change it according to my theme. Then i do something like this
//This is in my constants file
public static int CURRENT_THEME = R.style.AppTheme;
//This is in my onCreate of every Activity.
setTheme(Constants.CURRENT_THEME);
setContentView(R.layout.activity_layout);
Hope this helps.
Yes you can set Theme like this:
activity.setTheme(R.style.theme_large);
activity.setTheme(R.style.theme_small);
<style name="theme_large">
<item name="main_background">#drawable/background_red</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="button_light">#color/button_light</item>
</style>
<style name="theme_small">
<item name="main_background">#drawable/background_red</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="button_light">#color/button_light</item>
</style>
Create Two Style
setTheme(darkTheme ? R.style.AppThemeDark : R.style.AppThemeLight);
<style name="AppThemeDark">
<item name="main_background">#drawable/background_dark</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="button_light">#color/button_dark</item>
</style>
<style name="AppThemeLight">
<item name="main_background">#drawable/background_light</item>
<item name="colorPrimaryDark">#color/colorPrimaryLight</item>
<item name="button_light">#color/button_light</item>
</style>
I think, setting theme after a button click or option choosen could be harsh for an Activity to handle.
What I am suggesting you is to reload your activity on button click but before that simply save the style_name , the user want to apply in internal memory or Shared Preferences. You can apply shared preference simply looking at here.
At the start of onCreate of your activity, apply that fetching part of shared preferences and apply the theme as user has indicated. This would help you to preserve the theme for that user until s/he uninstall that application or clears the app data.
If s/he is using the application for first time, the stored style_name string would be null so load your application with default theme.
You can simply reload your activity on button click by using the below code:
public void onClick (View v){
Intent intent = getIntent();
finish();
startActivity(intent);
}
Hope it helps !!

Android: How can I remove the title bar without removing splitactionbar at the bottom?

Yeah pretty much the title. I tried different android styles, but I lose both the title and the action bar at the bottom. I also tried using
getActionBar().setDisplayShowTitleEnabled(false);
getActionBar().setHomeButtonEnabled(false);
getActionBar().setDisplayUseLogoEnabled(false);
But with this I get a blank title bar. I want to remove the title bar completely. Does anyone know a solution for this? Thanks!
If you are using Theme.Holo.Light and want to use the Theme.Holo.Light.NoTitleBarBar variant on pre 3.2 devices you can add this to your styles.xml:
<style name="NoTitleBar" parent="#android:style/Theme.Holo.Light">
<item name="android:windowActionBar">true</item>
<item name="android:windowNoTitle">false</item>
and then set it as your activity's theme:
<activity android:theme="#style/NoTitleBar" ... />
In your oncreate do this
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
I found a solution: It is pretty much
<style name="MyActionBarStyle" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:displayOptions"></item>
<item name="android:height">0dip</item>
</style>
I just sized it to zero and it works.

How to set dialog (Custom) a glittering effect?

In my android app, I've designed some layouts to set the custom dialog. But I face some problems while making border with glittering effect.
I've set the following style to my dialog:
<style name="MyDialog" parent="android:Theme.Holo.Light.Dialog">
<item name="android:windowTitleStyle">#style/DialogWindowTitle</item>
<item name="android:windowFrame">#color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFrame">#drawable/alertbgc</item>
In the java snippet,I added the lines as follows:
final Dialog mydialog= new Dialog(this,R.style.MyDialog);
mydialog.setContentView(R.layout.mylayout);
But with this snippets I'm getting very dark background (I used nine patch images too, but no use). Please help me providing your ideas.
Thanks in advance

Change the Dialog style using a theme

I was wondering whether there is a simple way to tell Android to always use a custom style to display Dialogs.
Using themes and styles you can change the look and feel of all, say, TextViews using this piece of code when defining a theme in themes.xml:
<item name="android:textViewStyle">#style/Blue.TextView</item>
with Blue.TextView being defined in styles.xml.
Is there some way to do so for Dialogs as well ?
yes, there is. for example,
AlertDialog.Builder b = new AlertDialog.Builder(context, R.style.MyTheme);
or, if you are using a DialogFragment, just call the setStyle() method,
<style
name="Theme_Dialog_Translucent"
parent="android:Theme.Dialog">
<item
name="android:windowBackground">#null</item>
</style>
Below is the working code::
Dialog mDialog = new Dialog(this,R.style.ThemeDialogCustom);
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.setCanceledOnTouchOutside(true); //But here It is not workin
mDialog.setContentView(R.layout.popup);

Categories